Commit cb27f278 authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

up

parent 6c4cf463
...@@ -10,6 +10,7 @@ require ( ...@@ -10,6 +10,7 @@ require (
github.com/google/uuid v1.3.0 github.com/google/uuid v1.3.0
github.com/jackc/pgx/v5 v5.4.2 github.com/jackc/pgx/v5 v5.4.2
github.com/patrickmn/go-cache v2.1.0+incompatible github.com/patrickmn/go-cache v2.1.0+incompatible
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
) )
require ( require (
......
...@@ -30,8 +30,8 @@ github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= ...@@ -30,8 +30,8 @@ github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
...@@ -102,6 +102,8 @@ golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= ...@@ -102,6 +102,8 @@ golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw=
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
...@@ -112,7 +114,6 @@ golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= ...@@ -112,7 +114,6 @@ golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
......
...@@ -278,7 +278,7 @@ func (d *Pool) setNotAliveConn(conn *Conn) { ...@@ -278,7 +278,7 @@ func (d *Pool) setNotAliveConn(conn *Conn) {
if slave == conn { if slave == conn {
conn.Alive = false conn.Alive = false
d.notAliveConns = append(d.notAliveConns, conn) d.notAliveConns = append(d.notAliveConns, conn)
d.SrvSync = zutils.Remove(d.SrvSync, i) d.SrvSync = zutils.ArrayRemove(d.SrvSync, i)
return return
} }
} }
...@@ -287,7 +287,7 @@ func (d *Pool) setNotAliveConn(conn *Conn) { ...@@ -287,7 +287,7 @@ func (d *Pool) setNotAliveConn(conn *Conn) {
if slave == conn { if slave == conn {
conn.Alive = false conn.Alive = false
d.notAliveConns = append(d.notAliveConns, conn) d.notAliveConns = append(d.notAliveConns, conn)
d.SrvAsync = zutils.Remove(d.SrvAsync, i) d.SrvAsync = zutils.ArrayRemove(d.SrvAsync, i)
return return
} }
...@@ -307,7 +307,7 @@ func (d *Pool) Start() { ...@@ -307,7 +307,7 @@ func (d *Pool) Start() {
if err := d.ping(q); err == nil { if err := d.ping(q); err == nil {
d.mu.Lock() d.mu.Lock()
q.Alive = true q.Alive = true
d.notAliveConns = zutils.Remove(d.notAliveConns, i) d.notAliveConns = zutils.ArrayRemove(d.notAliveConns, i)
if q.Mode == ConnModeSync { if q.Mode == ConnModeSync {
d.SrvSync = append(d.SrvSync, q) d.SrvSync = append(d.SrvSync, q)
} else if q.Mode == ConnModeAsync { } else if q.Mode == ConnModeAsync {
......
package zdwh
import "github.com/gin-gonic/gin"
func TableHandler(c *gin.Context) {
}
package zerr
package zutils
import (
"golang.org/x/exp/constraints"
"reflect"
"sort"
)
func ArrayUnique[T comparable](s []T) []T {
keys := make(map[T]bool)
var list []T
for _, entry := range s {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}
func InArray[T comparable](needle T, haystack []T) bool {
for _, v := range haystack {
if needle == v {
return true
}
}
return false
}
func ArrayRemove[T comparable](slice []T, s int) []T {
return append(slice[:s], slice[s+1:]...)
}
func ArrayColumn[T comparable](input []map[string]T, columnKey string) []T {
columns := make([]T, 0, len(input))
for _, val := range input {
if v, ok := val[columnKey]; ok {
columns = append(columns, v)
}
}
return columns
}
func ArrayCombine[K, V comparable](keys []K, values []V) map[K]V {
if len(keys) != len(values) {
return nil
}
m := make(map[K]V, len(keys))
for i, v := range keys {
m[v] = values[i]
}
return m
}
func ArrayDiff[T comparable](array1, array2 []T) []T {
var res []T
for _, v := range array1 {
if !InArray(v, array2) {
res = append(res, v)
}
}
return res
}
func ArrayIntersect[T comparable](array1, array2 []T) []T {
var res []T
for _, v := range array1 {
if InArray(v, array2) {
res = append(res, v)
}
}
return res
}
func ArrayFlip(input any) any {
if input == nil {
return nil
}
val := reflect.ValueOf(input)
if val.Len() == 0 {
return nil
}
res := make(map[any]any, val.Len())
switch val.Kind() {
case reflect.Slice, reflect.Array:
for i := 0; i < val.Len(); i++ {
res[val.Index(i).Interface()] = i
}
return res
case reflect.Map:
for _, k := range val.MapKeys() {
res[val.MapIndex(k).Interface()] = k.Interface()
}
return res
}
return nil
}
func ArrayKeys(input any) any {
if input == nil {
return nil
}
val := reflect.ValueOf(input)
if val.Len() == 0 {
return nil
}
switch val.Kind() {
case reflect.Slice, reflect.Array:
var res []int
for i := 0; i < val.Len(); i++ {
res = append(res, i)
}
return res
case reflect.Map:
var res []string
for _, k := range val.MapKeys() {
res = append(res, k.String())
}
sort.SliceStable(res, func(i, j int) bool {
return res[i] < res[j]
})
return res
}
return nil
}
func ArrayKeyExists[K, V comparable](k K, m map[K]V) bool {
return KeyExists(k, m)
}
func KeyExists[K, V comparable](k K, m map[K]V) bool {
_, ok := m[k]
return ok
}
func ArrayFilter(input any, callback func(any) bool) any {
if input == nil {
return nil
}
val := reflect.ValueOf(input)
if val.Len() == 0 {
return nil
}
if callback == nil {
callback = func(v any) bool {
return v != nil
}
}
switch val.Kind() {
case reflect.Slice, reflect.Array:
var res []any
for i := 0; i < val.Len(); i++ {
v := val.Index(i).Interface()
if callback(v) {
res = append(res, v)
}
}
return res
case reflect.Map:
res := make(map[any]any)
for _, k := range val.MapKeys() {
v := val.MapIndex(k).Interface()
if callback(v) {
res[k.Interface()] = v
}
}
return res
}
return input
}
func ArrayPad[T comparable](array []T, size int, value T) []T {
if size == 0 || (size > 0 && size < len(array)) || (size < 0 && size > -len(array)) {
return array
}
n := size
if size < 0 {
n = -size
}
n -= len(array)
tmp := make([]T, n)
for i := 0; i < n; i++ {
tmp[i] = value
}
if size > 0 {
return append(array, tmp...)
}
return append(tmp, array...)
}
func ArrayPop[T comparable](s *[]T) T {
var t T
if s == nil || len(*s) == 0 {
return t
}
ep := len(*s) - 1
e := (*s)[ep]
*s = (*s)[:ep]
return e
}
func ArrayPush[T comparable](s *[]T, elements ...T) int {
if s == nil {
return 0
}
*s = append(*s, elements...)
return len(*s)
}
func ArrayShift[T comparable](s *[]T) T {
var t T
if s == nil || len(*s) == 0 {
return t
}
f := (*s)[0]
*s = (*s)[1:]
return f
}
func ArrayUnshift[T comparable](s *[]T, elements ...T) int {
if s == nil {
return 0
}
*s = append(elements, *s...)
return len(*s)
}
func ArrayReverse[T comparable](s []T) []T {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
return s
}
func ArraySlice[T comparable](array []T, offset, length uint) []T {
if offset > uint(len(array)) {
return nil
}
end := offset + length
if end < uint(len(array)) {
return array[offset:end]
}
return array[offset:]
}
func ArraySum[T constraints.Ordered](array []T) T {
var sum T
for _, v := range array {
sum += v
}
return sum
}
func Sort[T constraints.Ordered](array []T) []T {
if len(array) == 0 {
return array
}
sort.Slice(array, func(i int, j int) bool {
return array[i] < array[j]
})
return array
}
func Rsort[T constraints.Ordered](array []T) []T {
if len(array) == 0 {
return array
}
sort.Slice(array, func(i int, j int) bool {
return array[i] > array[j]
})
return array
}
package zutils package zutils
import "strings" import (
"fmt"
func Uniq[T comparable](s []T) []T { "strings"
keys := make(map[T]bool) )
var list []T
for _, entry := range s {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}
func Contains(s string, sl []string) bool { func Contains(s string, sl []string) bool {
for _, s2 := range sl { for _, s2 := range sl {
...@@ -26,6 +15,10 @@ func Contains(s string, sl []string) bool { ...@@ -26,6 +15,10 @@ func Contains(s string, sl []string) bool {
return false return false
} }
func Remove[T comparable](slice []T, s int) []T { func ReplaceArgs(s string, args map[string]any) string {
return append(slice[:s], slice[s+1:]...) for k, v := range args {
s = strings.ReplaceAll(s, "%"+k+"%", fmt.Sprintf("%v", v))
}
return s
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment