Explorar el Código

Connection

- draft
Alexey Kim hace 1 año
padre
commit
d4b61a1700
Se han modificado 2 ficheros con 63 adiciones y 0 borrados
  1. 16 0
      connection/cursor.go
  2. 47 0
      connection/slice.go

+ 16 - 0
connection/cursor.go

@@ -0,0 +1,16 @@
+package connection
+
+type Cursor interface {
+	NS() Namespace
+	ID() string
+
+	Cursor() string
+}
+
+type Namespace string
+
+const (
+	NSMatch  Namespace = "Match"
+	NSLeague Namespace = "League"
+	NSTeam   Namespace = "Team"
+)

+ 47 - 0
connection/slice.go

@@ -0,0 +1,47 @@
+package connection
+
+func Reverse[T any](slice []T) []T {
+	var reversed []T
+	for i := len(slice) - 1; i >= 0; i-- {
+		reversed = append(reversed, slice[i])
+	}
+
+	return reversed
+}
+
+func First[T any](slice []T, first *int) []T {
+	if len(slice) == 0 || first == nil {
+		return slice[:]
+	}
+
+	if *first > len(slice) {
+		*first = len(slice)
+	}
+
+	return slice[:*first]
+}
+
+func Last[T any](slice []T, last *int) []T {
+	if len(slice) < 1 {
+		return nil
+	}
+
+	if last == nil {
+		return slice[:]
+	}
+
+	if *last < 0 {
+		*last = 0
+	}
+
+	var i int
+	if *last >= len(slice) {
+		i = 0
+	} else if *last == 0 {
+		return nil
+	} else {
+		i = len(slice) - *last
+	}
+
+	return slice[i:]
+}