yjp 1 miesiąc temu
rodzic
commit
035b0038e3
89 zmienionych plików z 124 dodań i 683 usunięć
  1. 0 0
      .gitignore
  2. 0 0
      LICENSE
  3. 0 0
      README.md
  4. 0 0
      caller/caller.go
  5. 0 0
      caller/caller_test.go
  6. 0 0
      chinese/chinese.go
  7. 0 0
      chinese/chinese_test.go
  8. 0 0
      encoding/encoding.go
  9. 0 0
      encoding/encoding_test.go
  10. 0 0
      errutils/errutils.go
  11. 0 0
      excelutils/excelutils.go
  12. 0 0
      fileutils/fileutils.go
  13. 0 0
      fileutils/fileutils_test.go
  14. 0 0
      fileutils/test_dir/test.txt
  15. 0 0
      fileutils/test_dir/test_sub_dir/test_sub.txt
  16. 0 1
      go.mod
  17. 0 2
      go.sum
  18. 0 0
      http_client/http_client.go
  19. 1 1
      http_client/request.go
  20. 0 0
      imgutils/imgutils.go
  21. 0 0
      locaxis/locaxis.go
  22. 1 1
      maputils/maputils.go
  23. 0 0
      maputils/maputils_test.go
  24. 0 0
      money/money.go
  25. 0 0
      money/money_test.go
  26. 1 1
      mqtt_client/mqtt_client.go
  27. 0 0
      network/connection.go
  28. 0 0
      network/data_reader.go
  29. 0 0
      network/data_reader_test.go
  30. 0 0
      network/data_writer.go
  31. 0 0
      network/data_writer_test.go
  32. 0 0
      network/tcp_client.go
  33. 0 0
      network/tcp_server.go
  34. 0 0
      network/tcp_test.go
  35. 0 0
      network/udp_client.go
  36. 0 0
      network/udp_server.go
  37. 0 0
      network/udp_test.go
  38. 1 19
      oss/oss.go
  39. 0 0
      pipeline/README.md
  40. 0 0
      pipeline/component/base.go
  41. 1 1
      pipeline/component/component.go
  42. 1 1
      pipeline/component/flow/bi.go
  43. 1 1
      pipeline/component/flow/flow.go
  44. 1 1
      pipeline/component/flow/if.go
  45. 1 1
      pipeline/component/flow/loop.go
  46. 1 1
      pipeline/component/flow/range.go
  47. 1 1
      pipeline/component/flow/seq.go
  48. 0 0
      pipeline/component/global_run_params.go
  49. 1 1
      pipeline/definition.go
  50. 1 1
      pipeline/pipeline.go
  51. 0 0
      pipeline/run_token.go
  52. 0 0
      pipeline/test/def.yaml
  53. 0 0
      pipeline/test/pipeline_test.go
  54. 1 1
      pipeline/test/test_node/bool.go
  55. 1 1
      pipeline/test/test_node/println.go
  56. 0 0
      pipeline/test/value.yaml
  57. 1 1
      redis_client/redis_client.go
  58. 1 1
      redislock/lock.go
  59. 0 0
      redislock/lock_test.go
  60. 0 221
      reflectutils/maker.go
  61. 0 100
      reflectutils/maker_test.go
  62. 0 0
      reflectutils/type.go
  63. 7 7
      reflectutils/value.go
  64. 0 0
      regular/regular.go
  65. 0 27
      slice/slice.go
  66. 0 0
      slice/slice_test.go
  67. 0 0
      strutils/strutils.go
  68. 0 0
      strutils/strutils_test.go
  69. 0 0
      syncutils/sync_var.go
  70. 0 0
      syncutils/sync_var_test.go
  71. 0 0
      template/template.go
  72. 20 70
      template/template_func.go
  73. 0 26
      template/template_test.go
  74. 0 0
      template/test_tpl/test.yaml.tpl
  75. 0 0
      timeutils/timeutils.go
  76. 0 0
      timeutils/timeutils_test.go
  77. 0 0
      tree/tree.go
  78. 77 191
      websocket/websocket.go
  79. 0 0
      yaml/yaml_checker/README.md
  80. 0 0
      yaml/yaml_checker/log.go
  81. 0 0
      yaml/yaml_checker/schema.yaml
  82. 1 1
      yaml/yaml_checker/schema_doc.go
  83. 1 1
      yaml/yaml_checker/schema_node.go
  84. 0 0
      yaml/yaml_checker/test.yaml
  85. 0 0
      yaml/yaml_checker/utils.go
  86. 0 0
      yaml/yaml_checker/yaml_checker_test.go
  87. 0 0
      yaml/yaml_loader/test.yaml
  88. 1 1
      yaml/yaml_loader/yaml_loader.go
  89. 0 0
      yaml/yaml_loader/yaml_loader_test.go

+ 0 - 0
.gitignore


+ 0 - 0
LICENSE


+ 0 - 0
README.md


+ 0 - 0
caller/caller.go


+ 0 - 0
caller/caller_test.go


+ 0 - 0
chinese/chinese.go


+ 0 - 0
chinese/chinese_test.go


+ 0 - 0
encoding/encoding.go


+ 0 - 0
encoding/encoding_test.go


+ 0 - 0
errutils/errutils.go


+ 0 - 0
excelutils/excelutils.go


+ 0 - 0
fileutils/fileutils.go


+ 0 - 0
fileutils/fileutils_test.go


+ 0 - 0
fileutils/test_dir/test.txt


+ 0 - 0
fileutils/test_dir/test_sub_dir/test_sub.txt


+ 0 - 1
go.mod

@@ -13,7 +13,6 @@ require (
 	github.com/mitchellh/mapstructure v1.5.0
 	github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
 	github.com/olahol/melody v1.2.1
-	github.com/pkg/errors v0.9.1
 	github.com/redis/go-redis/v9 v9.4.0
 	github.com/satori/go.uuid v1.2.0
 	github.com/shopspring/decimal v1.2.0

+ 0 - 2
go.sum

@@ -49,8 +49,6 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6
 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
 github.com/olahol/melody v1.2.1 h1:xdwRkzHxf+B0w4TKbGpUSSkV516ZucQZJIWLztOWICQ=
 github.com/olahol/melody v1.2.1/go.mod h1:GgkTl6Y7yWj/HtfD48Q5vLKPVoZOH+Qqgfa7CvJgJM4=
-github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
-github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/redis/go-redis/v9 v9.4.0 h1:Yzoz33UZw9I/mFhx4MNrB6Fk+XHO1VukNcCa1+lwyKk=

+ 0 - 0
http_client/http_client.go


+ 1 - 1
http_client/request.go

@@ -2,8 +2,8 @@ package http_client
 
 import (
 	"encoding/json"
+	"errors"
 	"github.com/go-resty/resty/v2"
-	"github.com/pkg/errors"
 )
 
 type RequestOption func(request *Request)

+ 0 - 0
imgutils/imgutils.go


+ 0 - 0
locaxis/locaxis.go


+ 1 - 1
maputils/maputils.go

@@ -1,7 +1,7 @@
 package maputils
 
 import (
-	"github.com/pkg/errors"
+	"errors"
 	"strconv"
 	"strings"
 )

+ 0 - 0
maputils/maputils_test.go


+ 0 - 0
money/money.go


+ 0 - 0
money/money_test.go


+ 1 - 1
mqtt_client/mqtt_client.go

@@ -2,9 +2,9 @@ package mqtt_client
 
 import (
 	"encoding/json"
+	"errors"
 	"git.sxidc.com/go-tools/utils/strutils"
 	mqtt "github.com/eclipse/paho.mqtt.golang"
-	"github.com/pkg/errors"
 	"log"
 	"sync"
 	"time"

+ 0 - 0
network/connection.go


+ 0 - 0
network/data_reader.go


+ 0 - 0
network/data_reader_test.go


+ 0 - 0
network/data_writer.go


+ 0 - 0
network/data_writer_test.go


+ 0 - 0
network/tcp_client.go


+ 0 - 0
network/tcp_server.go


+ 0 - 0
network/tcp_test.go


+ 0 - 0
network/udp_client.go


+ 0 - 0
network/udp_server.go


+ 0 - 0
network/udp_test.go


+ 1 - 19
oss/oss.go

@@ -2,9 +2,9 @@ package oss
 
 import (
 	"bytes"
+	"errors"
 	"git.sxidc.com/go-tools/utils/strutils"
 	"github.com/aliyun/aliyun-oss-go-sdk/oss"
-	"github.com/pkg/errors"
 	"io"
 	"log"
 )
@@ -134,24 +134,6 @@ func Ls(dir string) ([]string, error) {
 	return ks, nil
 }
 
-func LsWithoutPrefix(dir string) ([]string, error) {
-	if strutils.HasBlank(dir) {
-		return []string{}, nil
-	}
-
-	v2, err := Bkt.ListObjectsV2(oss.Prefix(dir))
-	if err != nil {
-		return nil, err
-	}
-
-	ks := make([]string, len(v2.Objects))
-	for i, obj := range v2.Objects {
-		ks[i] = obj.Key
-	}
-
-	return ks, nil
-}
-
 type ObjectInfo struct {
 	Key  string
 	Type string

+ 0 - 0
pipeline/README.md


+ 0 - 0
pipeline/component/base.go


+ 1 - 1
pipeline/component/component.go

@@ -1,8 +1,8 @@
 package component
 
 import (
+	"errors"
 	"git.sxidc.com/go-tools/utils/strutils"
-	"github.com/pkg/errors"
 	"sync"
 )
 

+ 1 - 1
pipeline/component/flow/bi.go

@@ -1,9 +1,9 @@
 package flow
 
 import (
+	"errors"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
 	"github.com/mitchellh/mapstructure"
-	"github.com/pkg/errors"
 )
 
 const (

+ 1 - 1
pipeline/component/flow/flow.go

@@ -1,9 +1,9 @@
 package flow
 
 import (
+	"errors"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
 	"git.sxidc.com/go-tools/utils/strutils"
-	"github.com/pkg/errors"
 )
 
 type SubComponentBuildParams struct {

+ 1 - 1
pipeline/component/flow/if.go

@@ -1,10 +1,10 @@
 package flow
 
 import (
+	"errors"
 	"fmt"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
 	"github.com/mitchellh/mapstructure"
-	"github.com/pkg/errors"
 )
 
 const (

+ 1 - 1
pipeline/component/flow/loop.go

@@ -1,10 +1,10 @@
 package flow
 
 import (
+	"errors"
 	"fmt"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
 	"github.com/mitchellh/mapstructure"
-	"github.com/pkg/errors"
 )
 
 const (

+ 1 - 1
pipeline/component/flow/range.go

@@ -1,9 +1,9 @@
 package flow
 
 import (
+	"errors"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
 	"github.com/mitchellh/mapstructure"
-	"github.com/pkg/errors"
 )
 
 const (

+ 1 - 1
pipeline/component/flow/seq.go

@@ -1,9 +1,9 @@
 package flow
 
 import (
+	"errors"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
 	"github.com/mitchellh/mapstructure"
-	"github.com/pkg/errors"
 )
 
 const (

+ 0 - 0
pipeline/component/global_run_params.go


+ 1 - 1
pipeline/definition.go

@@ -1,11 +1,11 @@
 package pipeline
 
 import (
+	"errors"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
 	"git.sxidc.com/go-tools/utils/pipeline/component/flow"
 	"git.sxidc.com/go-tools/utils/strutils"
 	"github.com/fatih/structs"
-	"github.com/pkg/errors"
 )
 
 type Definition struct {

+ 1 - 1
pipeline/pipeline.go

@@ -1,11 +1,11 @@
 package pipeline
 
 import (
+	"errors"
 	"git.sxidc.com/go-tools/utils/fileutils"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
 	"git.sxidc.com/go-tools/utils/pipeline/component/flow"
 	"git.sxidc.com/go-tools/utils/strutils"
-	"github.com/pkg/errors"
 	"gopkg.in/yaml.v3"
 	"os"
 )

+ 0 - 0
pipeline/run_token.go


+ 0 - 0
pipeline/test/def.yaml


+ 0 - 0
pipeline/test/pipeline_test.go


+ 1 - 1
pipeline/test/test_node/bool.go

@@ -1,11 +1,11 @@
 package test_node
 
 import (
+	"errors"
 	"fmt"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
 	"git.sxidc.com/go-tools/utils/strutils"
 	"github.com/mitchellh/mapstructure"
-	"github.com/pkg/errors"
 	"math/rand"
 )
 

+ 1 - 1
pipeline/test/test_node/println.go

@@ -1,11 +1,11 @@
 package test_node
 
 import (
+	"errors"
 	"fmt"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
 	"git.sxidc.com/go-tools/utils/pipeline/component/flow"
 	"github.com/mitchellh/mapstructure"
-	"github.com/pkg/errors"
 )
 
 const (

+ 0 - 0
pipeline/test/value.yaml


+ 1 - 1
redis_client/redis_client.go

@@ -2,7 +2,7 @@ package redis_client
 
 import (
 	"context"
-	"github.com/pkg/errors"
+	"errors"
 	"github.com/redis/go-redis/v9"
 	"time"
 )

+ 1 - 1
redislock/lock.go

@@ -2,7 +2,7 @@ package redislock
 
 import (
 	"context"
-	"github.com/pkg/errors"
+	"errors"
 	"github.com/redis/go-redis/v9"
 	"time"
 )

+ 0 - 0
redislock/lock_test.go


+ 0 - 221
reflectutils/maker.go

@@ -1,221 +0,0 @@
-package reflectutils
-
-import (
-	"fmt"
-	"reflect"
-)
-
-type StructFieldDefinition struct {
-	Name string
-	Type reflect.Type
-	Tag  string
-}
-
-type StructMethodDefinition struct {
-	Name             string
-	ArgTypes         []reflect.Type
-	ReturnValueTypes []reflect.Type
-	Body             func(this *Struct, args ...any) []any
-}
-
-type Struct struct {
-	structValueElem reflect.Value
-	fieldMap        map[string]reflect.Value
-	methodMap       map[string]reflect.Value
-}
-
-func NewStruct(fields ...StructFieldDefinition) *Struct {
-	if len(fields) == 0 {
-		return &Struct{
-			structValueElem: reflect.ValueOf(struct{}{}),
-		}
-	}
-
-	reflectStructFields := make([]reflect.StructField, len(fields))
-	for i, field := range fields {
-		reflectStructFields[i] = reflect.StructField{
-			Name: field.Name,
-			Type: field.Type,
-			Tag:  reflect.StructTag(field.Tag),
-		}
-	}
-
-	return &Struct{
-		structValueElem: reflect.New(reflect.StructOf(reflectStructFields)).Elem(),
-		fieldMap:        map[string]reflect.Value{},
-		methodMap:       map[string]reflect.Value{},
-	}
-}
-
-func (s *Struct) Any() any {
-	return s.structValueElem.Interface()
-}
-
-func (s *Struct) Pointer() any {
-	return s.structValueElem.Addr().Interface()
-}
-
-func (s *Struct) SetFieldValue(fieldName string, value any) {
-	s.loadFieldValue(fieldName).Set(reflect.ValueOf(value))
-}
-
-func (s *Struct) FieldValue(fieldName string) any {
-	return s.loadFieldValue(fieldName).Interface()
-}
-
-func (s *Struct) SetFieldValues(fieldAndValues map[string]any) {
-	for fieldName, value := range fieldAndValues {
-		s.SetFieldValue(fieldName, value)
-	}
-}
-
-func (s *Struct) FieldValues(fieldNames ...string) map[string]any {
-	if len(fieldNames) == 0 {
-		return map[string]any{}
-	}
-
-	fieldAndValues := make(map[string]any)
-	for _, fieldName := range fieldNames {
-		fieldAndValues[fieldName] = s.FieldValue(fieldName)
-	}
-
-	return fieldAndValues
-}
-
-func (s *Struct) MakeMethod(methods ...StructMethodDefinition) {
-	for _, method := range methods {
-		argTypes := make([]reflect.Type, 0)
-		argTypes = append(argTypes, s.structValueElem.Type())
-		argTypes = append(argTypes, method.ArgTypes...)
-
-		funcValue := reflect.MakeFunc(reflect.FuncOf(argTypes, method.ReturnValueTypes, false),
-			func(argValues []reflect.Value) []reflect.Value {
-				args := make([]any, len(argValues)-1)
-				for i, arg := range argValues {
-					if i == 0 {
-						continue
-					}
-
-					args[i-1] = arg.Interface()
-				}
-
-				returns := method.Body(s, args)
-
-				returnValues := make([]reflect.Value, len(returns))
-				for j, returnValue := range returns {
-					reflectValue := reflect.ValueOf(returnValue)
-					if !reflectValue.IsValid() {
-						returnValues[j] = reflect.Zero(method.ReturnValueTypes[j])
-					} else {
-						returnValues[j] = reflect.ValueOf(returnValue)
-					}
-				}
-
-				return returnValues
-			})
-
-		s.methodMap[method.Name] = funcValue
-	}
-}
-
-func (s *Struct) CallMethod(methodName string, args ...any) []any {
-	method, ok := s.methodMap[methodName]
-	if !ok {
-		panic(fmt.Sprintf("%s方法不存在", methodName))
-	}
-
-	argValues := make([]reflect.Value, len(args)+1)
-	argValues[0] = s.structValueElem
-	for i, arg := range args {
-		argValues[i+1] = reflect.ValueOf(arg)
-	}
-
-	returnValues := method.Call(argValues)
-
-	returns := make([]any, len(returnValues))
-	for j, returnValue := range returnValues {
-		if returnValue.IsNil() {
-			returns[j] = nil
-		} else {
-			returns[j] = returnValue.Interface()
-		}
-	}
-
-	return returns
-}
-
-func (s *Struct) loadFieldValue(fieldName string) reflect.Value {
-	fieldValue, ok := s.fieldMap[fieldName]
-	if ok {
-		return fieldValue
-	}
-
-	fieldValue = s.structValueElem.FieldByName(fieldName)
-	if !fieldValue.IsValid() {
-		panic(fmt.Sprintf("%s字段不存在", fieldName))
-	}
-
-	return fieldValue
-}
-
-type FunctionDefinition struct {
-	ArgTypes         []reflect.Type
-	ReturnValueTypes []reflect.Type
-	Body             func(args ...any) []any
-}
-
-type Function struct {
-	functionValue reflect.Value
-}
-
-func (f *Function) Call(args ...any) []any {
-	argValues := make([]reflect.Value, len(args))
-	for i, arg := range args {
-		argValues[i] = reflect.ValueOf(arg)
-	}
-
-	returnValues := f.functionValue.Call(argValues)
-
-	returns := make([]any, len(returnValues))
-	for j, returnValue := range returnValues {
-		if returnValue.IsNil() {
-			returns[j] = nil
-		} else {
-			returns[j] = returnValue.Interface()
-		}
-	}
-
-	return returns
-}
-
-func MakeFunction(function FunctionDefinition) *Function {
-	funcValue := reflect.MakeFunc(reflect.FuncOf(function.ArgTypes, function.ReturnValueTypes, false),
-		func(argValues []reflect.Value) []reflect.Value {
-			args := make([]any, len(argValues)-1)
-			for i, arg := range argValues {
-				if i == 0 {
-					continue
-				}
-
-				args[i-1] = arg.Interface()
-			}
-
-			returns := function.Body(args)
-
-			returnValues := make([]reflect.Value, len(returns))
-			for j, returnValue := range returns {
-				reflectValue := reflect.ValueOf(returnValue)
-				if !reflectValue.IsValid() {
-					returnValues[j] = reflect.Zero(function.ReturnValueTypes[j])
-				} else {
-					returnValues[j] = reflect.ValueOf(returnValue)
-				}
-			}
-
-			return returnValues
-		})
-
-	return &Function{
-		functionValue: funcValue,
-	}
-}

+ 0 - 100
reflectutils/maker_test.go

@@ -1,100 +0,0 @@
-package reflectutils
-
-import (
-	"fmt"
-	"github.com/pkg/errors"
-	"reflect"
-	"testing"
-	"time"
-)
-
-func TestStruct(t *testing.T) {
-	name := "test"
-	age := 18
-	enterTime := time.Now().Local()
-
-	studentStruct := NewStruct(
-		StructFieldDefinition{
-			Name: "Name",
-			Type: reflect.TypeOf(""),
-			Tag:  "json:name",
-		},
-		StructFieldDefinition{
-			Name: "Age",
-			Type: reflect.TypeOf(0),
-			Tag:  "json:age",
-		},
-		StructFieldDefinition{
-			Name: "EnterTime",
-			Type: reflect.TypeOf(time.Time{}),
-			Tag:  "json:enterTime",
-		},
-	)
-
-	studentStruct.SetFieldValues(map[string]any{
-		"Name":      name,
-		"Age":       age,
-		"EnterTime": enterTime,
-	})
-
-	values := studentStruct.FieldValues("Name", "Age", "EnterTime")
-
-	for fieldName, value := range values {
-		switch fieldName {
-		case "Name":
-			if value != name {
-				t.Fatalf("%+v\n", errors.Errorf("名字不一致: except: %v, actual: %v", name, value))
-			}
-		case "Age":
-			if value != age {
-				t.Fatalf("%+v\n", errors.Errorf("年龄不一致: except: %v, actual: %v", age, value))
-			}
-		case "EnterTime":
-			if value != enterTime {
-				t.Fatalf("%+v\n", errors.Errorf("入学时间不一致: except: %v, actual: %v", enterTime, value))
-			}
-		default:
-			t.Fatalf("%+v\n", errors.New("不存在的字段"))
-		}
-	}
-
-	studentStruct.MakeMethod(
-		StructMethodDefinition{
-			Name:             "Print",
-			ArgTypes:         []reflect.Type{reflect.TypeOf("")},
-			ReturnValueTypes: []reflect.Type{reflect.TypeOf(errors.New(""))},
-			Body: func(s *Struct, args ...any) []any {
-				values := studentStruct.FieldValues("Name", "Age", "EnterTime")
-
-				fmt.Println("Student Info:")
-				fmt.Println("Name:", values["Name"])
-				fmt.Println("Age:", values["Age"])
-				fmt.Println("EnterTime:", values["EnterTime"].(time.Time).Format(time.DateTime))
-				fmt.Println("Arg:", args[0])
-
-				return []any{nil}
-			},
-		},
-	)
-
-	returns := studentStruct.CallMethod("Print", "Hello Args")
-	if returns[0] != nil {
-		t.Fatalf("%+v\n", errors.Errorf("%v", returns[0]))
-	}
-}
-
-func TestFunction(t *testing.T) {
-	printHelloFunc := MakeFunction(FunctionDefinition{
-		ArgTypes:         []reflect.Type{reflect.TypeOf("")},
-		ReturnValueTypes: []reflect.Type{reflect.TypeOf(errors.New(""))},
-		Body: func(args ...any) []any {
-			fmt.Printf("Hello %v!\n", args[0])
-			return []any{nil}
-		},
-	})
-
-	returns := printHelloFunc.Call("World")
-	if returns[0] != nil {
-		t.Fatalf("%+v\n", errors.Errorf("%v", returns[0]))
-	}
-}

+ 0 - 0
reflectutils/type.go


+ 7 - 7
reflectutils/value.go

@@ -1,7 +1,7 @@
 package reflectutils
 
 import (
-	"github.com/pkg/errors"
+	"errors"
 	"reflect"
 	"strconv"
 )
@@ -204,7 +204,7 @@ func ToString(data any) (string, error) {
 		elemKind := dataVal.Type().Elem().Kind()
 
 		if elemKind != reflect.Uint8 {
-			return "", errors.New("不支持的类型: " + dataVal.Type().String())
+			return "", errors.New("不支持的类型: " + dataVal.Type().Elem().String())
 		}
 
 		var uints []uint8
@@ -219,7 +219,7 @@ func ToString(data any) (string, error) {
 
 		return string(uints), nil
 	default:
-		return "", errors.New("不支持的类型: " + dataVal.Type().String())
+		return "", errors.New("不支持的类型: " + dataVal.Type().Elem().String())
 	}
 }
 
@@ -253,7 +253,7 @@ func ToInt64(data any) (int64, error) {
 
 		return strconv.ParseInt(str, 0, 10)
 	default:
-		return 0, errors.New("不支持的类型: " + dataVal.Type().String())
+		return 0, errors.New("不支持的类型: " + dataVal.Type().Elem().String())
 	}
 }
 
@@ -287,7 +287,7 @@ func ToUint64(data any) (uint64, error) {
 
 		return strconv.ParseUint(str, 0, 10)
 	default:
-		return 0, errors.New("不支持的类型: " + dataVal.Type().String())
+		return 0, errors.New("不支持的类型: " + dataVal.Type().Elem().String())
 	}
 }
 
@@ -316,7 +316,7 @@ func ToBool(data any) (bool, error) {
 			return strconv.ParseBool(dataVal.String())
 		}
 	default:
-		return false, errors.New("不支持的类型: " + dataVal.Type().String())
+		return false, errors.New("不支持的类型: " + dataVal.Type().Elem().String())
 	}
 }
 
@@ -350,7 +350,7 @@ func ToFloat64(data any) (float64, error) {
 
 		return strconv.ParseFloat(str, 10)
 	default:
-		return 0, errors.New("不支持的类型: " + dataVal.Type().String())
+		return 0, errors.New("不支持的类型: " + dataVal.Type().Elem().String())
 	}
 }
 

+ 0 - 0
regular/regular.go


+ 0 - 27
slice/slice.go

@@ -45,30 +45,3 @@ func ExtractValue[T any, R any](s []T, addTo func(v T) (R, bool)) []R {
 
 	return retSlice
 }
-
-func ExtractIntersectionValue[T comparable](aList, bList []T) []T {
-	aList = RemoveRepeatElement(aList)
-	bList = RemoveRepeatElement(bList)
-	cList := make([]T, 0)
-
-	tmpMap := make(map[T]int)
-	for _, item := range aList {
-		tmpMap[item] = 0
-	}
-
-	for _, item := range bList {
-		if _, ok := tmpMap[item]; ok {
-			cList = append(cList, item)
-		}
-	}
-
-	return cList
-}
-
-func ExtractUnionValue[T comparable](aList, bList []T) []T {
-	cList := make([]T, 0)
-	cList = append(cList, aList...)
-	cList = append(cList, bList...)
-	cList = RemoveRepeatElement(cList)
-	return cList
-}

+ 0 - 0
slice/slice_test.go


+ 0 - 0
strutils/strutils.go


+ 0 - 0
strutils/strutils_test.go


+ 0 - 0
syncutils/sync_var.go


+ 0 - 0
syncutils/sync_var_test.go


+ 0 - 0
template/template.go


+ 20 - 70
template/template_func.go

@@ -63,102 +63,52 @@ func UpperShort(s string) string {
 }
 
 func Id(s string) string {
-	if strings.HasSuffix(s, "ID") {
-		index := strings.LastIndex(s, "ID")
-		return s[0:index] + "Id"
+	if s == "ID" {
+		return "id"
 	}
 
-	if strings.HasSuffix(s, "id") {
-		index := strings.LastIndex(s, "id")
-		return s[0:index] + "Id"
+	if strings.Contains(s, "ID") {
+		return strings.ReplaceAll(s, "ID", "Id")
 	}
 
-	if strings.HasSuffix(s, "iD") {
-		index := strings.LastIndex(s, "iD")
-		return s[0:index] + "Id"
+	if strings.Contains(s, "id") {
+		return strings.ReplaceAll(s, "id", "Id")
 	}
 
-	if strings.HasSuffix(s, "IDs") {
-		index := strings.LastIndex(s, "IDs")
-		return s[0:index] + "Ids"
-	}
-
-	if strings.HasSuffix(s, "ids") {
-		index := strings.LastIndex(s, "ids")
-		return s[0:index] + "Ids"
-	}
-
-	if strings.HasSuffix(s, "iDs") {
-		index := strings.LastIndex(s, "iDs")
-		return s[0:index] + "Ids"
+	if strings.Contains(s, "iD") {
+		return strings.ReplaceAll(s, "iD", "Id")
 	}
 
 	return s
 }
 
 func ID(s string) string {
-	if strings.HasSuffix(s, "Id") {
-		index := strings.LastIndex(s, "Id")
-		return s[0:index] + "ID"
-	}
-
-	if strings.HasSuffix(s, "id") {
-		index := strings.LastIndex(s, "id")
-		return s[0:index] + "ID"
-	}
-
-	if strings.HasSuffix(s, "iD") {
-		index := strings.LastIndex(s, "iD")
-		return s[0:index] + "ID"
+	if strings.Contains(s, "Id") {
+		return strings.ReplaceAll(s, "Id", "ID")
 	}
 
-	if strings.HasSuffix(s, "Ids") {
-		index := strings.LastIndex(s, "Ids")
-		return s[0:index] + "IDs"
+	if strings.Contains(s, "id") {
+		return strings.ReplaceAll(s, "id", "ID")
 	}
 
-	if strings.HasSuffix(s, "ids") {
-		index := strings.LastIndex(s, "ids")
-		return s[0:index] + "IDs"
-	}
-
-	if strings.HasSuffix(s, "iDs") {
-		index := strings.LastIndex(s, "iDs")
-		return s[0:index] + "IDs"
+	if strings.Contains(s, "iD") {
+		return strings.ReplaceAll(s, "iD", "ID")
 	}
 
 	return s
 }
 
 func id(s string) string {
-	if strings.HasSuffix(s, "Id") {
-		index := strings.LastIndex(s, "Id")
-		return s[0:index] + "id"
-	}
-
-	if strings.HasSuffix(s, "ID") {
-		index := strings.LastIndex(s, "ID")
-		return s[0:index] + "id"
-	}
-
-	if strings.HasSuffix(s, "iD") {
-		index := strings.LastIndex(s, "iD")
-		return s[0:index] + "id"
-	}
-
-	if strings.HasSuffix(s, "Ids") {
-		index := strings.LastIndex(s, "Ids")
-		return s[0:index] + "ids"
+	if strings.Contains(s, "Id") {
+		return strings.ReplaceAll(s, "Id", "id")
 	}
 
-	if strings.HasSuffix(s, "IDs") {
-		index := strings.LastIndex(s, "IDs")
-		return s[0:index] + "ids"
+	if strings.Contains(s, "ID") {
+		return strings.ReplaceAll(s, "ID", "id")
 	}
 
-	if strings.HasSuffix(s, "iDs") {
-		index := strings.LastIndex(s, "iDs")
-		return s[0:index] + "ids"
+	if strings.Contains(s, "iD") {
+		return strings.ReplaceAll(s, "iD", "id")
 	}
 
 	return s

+ 0 - 26
template/template_test.go

@@ -124,29 +124,3 @@ func TestParseTemplateStringToBytes(t *testing.T) {
 		t.Fatal("渲染后的模板值不一致")
 	}
 }
-
-func TestIDTemplateFunc(t *testing.T) {
-	if Id("MiddleID") != "MiddleId" {
-		t.Fatal("Id转换错误")
-	}
-
-	if id("MiddleID") != "Middleid" {
-		t.Fatal("Id转换错误")
-	}
-
-	if ID("Middleid") != "MiddleID" {
-		t.Fatal("Id转换错误")
-	}
-
-	if Id("MiddleIDs") != "MiddleIds" {
-		t.Fatal("Id转换错误")
-	}
-
-	if id("MiddleIDs") != "Middleids" {
-		t.Fatal("Id转换错误")
-	}
-
-	if ID("Middleids") != "MiddleIDs" {
-		t.Fatal("Id转换错误")
-	}
-}

+ 0 - 0
template/test_tpl/test.yaml.tpl


+ 0 - 0
timeutils/timeutils.go


+ 0 - 0
timeutils/timeutils_test.go


+ 0 - 0
tree/tree.go


+ 77 - 191
websocket/websocket.go

@@ -2,45 +2,66 @@ package websocket
 
 import (
 	"github.com/olahol/melody"
-	"github.com/pkg/errors"
 	"net/http"
-	"sync"
 	"time"
 )
 
-type HandleConnectFunc func(context map[string]any)
-type HandleDisconnectFunc func(context map[string]any)
-type HandleErrorFunc func(err error, context map[string]any)
-type HandleCloseFunc func(i int, s string, context map[string]any) error
-type HandlePongFunc func(context map[string]any)
-type HandleMessageFunc func(message []byte, context map[string]any)
-type BroadCastFilterCallback func(context map[string]any) bool
+const (
+	groupIDKey           = "group-id"
+	connectionContextKey = "connection-context"
+)
+
+type HandleConnectFunc func(groupID string, context any)
+type HandleDisconnectFunc func(groupID string, context any)
+type HandleErrorFunc func(groupID string, err error, context any)
+type HandleCloseFunc func(groupID string, i int, s string, context any) error
+type HandlePongFunc func(groupID string, context any)
+type HandleMessageFunc func(groupID string, message []byte, context any)
 
 var managerInstance *Manager
 
-func Init() {
+func Init(opts ...InitOption) {
 	if managerInstance == nil {
-		managerInstance = &Manager{
-			melodyMapMutex: &sync.RWMutex{},
-			melodyMap:      make(map[string]*melody.Melody),
+		melodyInstance := melody.New()
+
+		options := new(InitOptions)
+		for _, opt := range opts {
+			opt(options)
+		}
+
+		if options.writeWaitSec != 0 {
+			melodyInstance.Config.WriteWait = time.Duration(options.writeWaitSec) * time.Second
+		}
+
+		if options.pongWaitSec != 0 {
+			melodyInstance.Config.PongWait = time.Duration(options.pongWaitSec) * time.Second
+		}
+
+		if options.pingPeriodSec != 0 {
+			melodyInstance.Config.PingPeriod = time.Duration(options.pingPeriodSec) * time.Second
+		}
+
+		if options.maxMessageSize != 0 {
+			melodyInstance.Config.MaxMessageSize = options.maxMessageSize
+		}
+
+		if options.messageBufferSize != 0 {
+			melodyInstance.Config.MessageBufferSize = options.messageBufferSize
 		}
+
+		melodyInstance.Config.ConcurrentMessageHandling = options.concurrentMessageHandling
+
+		melodyInstance.Upgrader.CheckOrigin = func(r *http.Request) bool { return true }
+		managerInstance = &Manager{melodyInstance: melodyInstance}
 	}
 }
 
 func Destroy() {
 	if managerInstance != nil {
-		managerInstance.melodyMapMutex.Lock()
-		defer managerInstance.melodyMapMutex.Unlock()
-
-		for _, melodyInstance := range managerInstance.melodyMap {
-			err := melodyInstance.Close()
-			if err != nil {
-				panic(err)
-			}
+		err := managerInstance.melodyInstance.Close()
+		if err != nil {
+			panic(err)
 		}
-
-		managerInstance.melodyMap = nil
-		managerInstance = nil
 	}
 
 	managerInstance = nil
@@ -51,132 +72,37 @@ func GetInstance() *Manager {
 }
 
 type Manager struct {
-	melodyMapMutex *sync.RWMutex
-	melodyMap      map[string]*melody.Melody
-}
-
-func (m *Manager) RegisterHub(groupID string, opts ...InitOption) {
-	m.melodyMapMutex.Lock()
-	defer m.melodyMapMutex.Unlock()
-
-	_, ok := m.melodyMap[groupID]
-	if ok {
-		return
-	}
-
-	melodyInstance := melody.New()
-
-	options := new(InitOptions)
-	for _, opt := range opts {
-		opt(options)
-	}
-
-	if options.writeWaitSec != 0 {
-		melodyInstance.Config.WriteWait = time.Duration(options.writeWaitSec) * time.Second
-	}
-
-	if options.pongWaitSec != 0 {
-		melodyInstance.Config.PongWait = time.Duration(options.pongWaitSec) * time.Second
-	}
-
-	if options.pingPeriodSec != 0 {
-		melodyInstance.Config.PingPeriod = time.Duration(options.pingPeriodSec) * time.Second
-	}
-
-	if options.maxMessageSize != 0 {
-		melodyInstance.Config.MaxMessageSize = options.maxMessageSize
-	}
-
-	if options.messageBufferSize != 0 {
-		melodyInstance.Config.MessageBufferSize = options.messageBufferSize
-	}
-
-	melodyInstance.Config.ConcurrentMessageHandling = options.concurrentMessageHandling
-
-	melodyInstance.Upgrader.CheckOrigin = func(r *http.Request) bool { return true }
-
-	m.melodyMap[groupID] = melodyInstance
+	melodyInstance *melody.Melody
 }
 
-func (m *Manager) UnregisterHub(groupID string) {
-	m.melodyMapMutex.Lock()
-	defer m.melodyMapMutex.Unlock()
-
-	melodyInstance, ok := m.melodyMap[groupID]
-	if !ok {
-		return
-	}
-
-	err := melodyInstance.Close()
-	if err != nil {
-		panic(err)
-	}
-
-	melodyInstance = nil
-
-	delete(m.melodyMap, groupID)
-}
-
-func (m *Manager) HandleConnect(groupID string, handleConnectFunc HandleConnectFunc) {
-	m.melodyMapMutex.RLock()
-	defer m.melodyMapMutex.RUnlock()
-
-	melodyInstance, ok := m.melodyMap[groupID]
-	if !ok {
-		return
-	}
-
-	melodyInstance.HandleConnect(func(session *melody.Session) {
+func (m *Manager) HandleConnect(handleConnectFunc HandleConnectFunc) {
+	m.melodyInstance.HandleConnect(func(session *melody.Session) {
 		if handleConnectFunc != nil {
-			handleConnectFunc(session.Keys)
+			handleConnectFunc(session.Keys[groupIDKey].(string), session.Keys[connectionContextKey])
 		}
 	})
 }
 
-func (m *Manager) HandleDisconnect(groupID string, handleDisconnectFunc HandleDisconnectFunc) {
-	m.melodyMapMutex.Lock()
-	defer m.melodyMapMutex.Unlock()
-
-	melodyInstance, ok := m.melodyMap[groupID]
-	if !ok {
-		return
-	}
-
-	melodyInstance.HandleDisconnect(func(session *melody.Session) {
+func (m *Manager) HandleDisconnect(handleDisconnectFunc HandleDisconnectFunc) {
+	m.melodyInstance.HandleDisconnect(func(session *melody.Session) {
 		if handleDisconnectFunc != nil {
-			handleDisconnectFunc(session.Keys)
+			handleDisconnectFunc(session.Keys[groupIDKey].(string), session.Keys[connectionContextKey])
 		}
 	})
 }
 
-func (m *Manager) HandleError(groupID string, handleErrorFunc HandleErrorFunc) {
-	m.melodyMapMutex.RLock()
-	defer m.melodyMapMutex.RUnlock()
-
-	melodyInstance, ok := m.melodyMap[groupID]
-	if !ok {
-		return
-	}
-
-	melodyInstance.HandleError(func(session *melody.Session, err error) {
+func (m *Manager) HandleError(handleErrorFunc HandleErrorFunc) {
+	m.melodyInstance.HandleError(func(session *melody.Session, err error) {
 		if handleErrorFunc != nil {
-			handleErrorFunc(err, session.Keys)
+			handleErrorFunc(session.Keys[groupIDKey].(string), err, session.Keys[connectionContextKey])
 		}
 	})
 }
 
-func (m *Manager) HandleClose(groupID string, handleCloseFunc HandleCloseFunc) {
-	m.melodyMapMutex.RLock()
-	defer m.melodyMapMutex.RUnlock()
-
-	melodyInstance, ok := m.melodyMap[groupID]
-	if !ok {
-		return
-	}
-
-	melodyInstance.HandleClose(func(session *melody.Session, i int, s string) error {
+func (m *Manager) HandleClose(handleCloseFunc HandleCloseFunc) {
+	m.melodyInstance.HandleClose(func(session *melody.Session, i int, s string) error {
 		if handleCloseFunc != nil {
-			err := handleCloseFunc(i, s, session.Keys)
+			err := handleCloseFunc(session.Keys[groupIDKey].(string), i, s, session.Keys[connectionContextKey])
 			if err != nil {
 				return err
 			}
@@ -186,38 +112,24 @@ func (m *Manager) HandleClose(groupID string, handleCloseFunc HandleCloseFunc) {
 	})
 }
 
-func (m *Manager) HandlePong(groupID string, handlePongFunc HandlePongFunc) {
-	m.melodyMapMutex.RLock()
-	defer m.melodyMapMutex.RUnlock()
-
-	melodyInstance, ok := m.melodyMap[groupID]
-	if !ok {
-		return
-	}
-
-	melodyInstance.HandlePong(func(session *melody.Session) {
+func (m *Manager) HandlePong(handlePongFunc HandlePongFunc) {
+	m.melodyInstance.HandlePong(func(session *melody.Session) {
 		if handlePongFunc != nil {
-			handlePongFunc(session.Keys)
+			handlePongFunc(session.Keys[groupIDKey].(string), session.Keys[connectionContextKey])
 		}
 	})
 }
 
 func (m *Manager) HandleRequest(groupID string, w http.ResponseWriter, r *http.Request, opts ...ConnectionOption) error {
-	m.melodyMapMutex.RLock()
-	defer m.melodyMapMutex.RUnlock()
-
-	melodyInstance, ok := m.melodyMap[groupID]
-	if !ok {
-		return errors.New("groupID尚未注册")
+	sessionMap := map[string]interface{}{
+		groupIDKey: groupID,
 	}
 
-	sessionMap := make(map[string]any)
-
 	for _, opt := range opts {
-		opt(&sessionMap)
+		opt(sessionMap)
 	}
 
-	err := melodyInstance.HandleRequestWithKeys(w, r, sessionMap)
+	err := m.melodyInstance.HandleRequestWithKeys(w, r, sessionMap)
 	if err != nil {
 		return err
 	}
@@ -225,47 +137,21 @@ func (m *Manager) HandleRequest(groupID string, w http.ResponseWriter, r *http.R
 	return nil
 }
 
-func (m *Manager) HandleMessage(groupID string, handleMessageFunc HandleMessageFunc) error {
-	m.melodyMapMutex.RLock()
-	defer m.melodyMapMutex.RUnlock()
-
-	melodyInstance, ok := m.melodyMap[groupID]
-	if !ok {
-		return errors.New("groupID尚未注册")
-	}
-
-	melodyInstance.HandleMessage(func(session *melody.Session, bytes []byte) {
+func (m *Manager) HandleMessage(handleMessageFunc HandleMessageFunc) {
+	m.melodyInstance.HandleMessage(func(session *melody.Session, bytes []byte) {
 		if handleMessageFunc != nil {
-			handleMessageFunc(bytes, session.Keys)
+			handleMessageFunc(session.Keys[groupIDKey].(string), bytes, session.Keys[connectionContextKey])
 		}
 	})
-
-	return nil
 }
 
 func (m *Manager) BroadCast(groupID string, msg []byte) error {
-	m.melodyMapMutex.RLock()
-	defer m.melodyMapMutex.RUnlock()
-
-	melodyInstance, ok := m.melodyMap[groupID]
-	if !ok {
-		return errors.New("groupID尚未注册")
-	}
-
-	return melodyInstance.Broadcast(msg)
-}
-
-func (m *Manager) BroadCastFilter(groupID string, msg []byte, filterCallback BroadCastFilterCallback) error {
-	m.melodyMapMutex.RLock()
-	defer m.melodyMapMutex.RUnlock()
-
-	melodyInstance, ok := m.melodyMap[groupID]
-	if !ok {
-		return errors.New("groupID尚未注册")
-	}
+	return m.melodyInstance.BroadcastFilter(msg, func(session *melody.Session) bool {
+		if session.Keys[groupIDKey] != groupID {
+			return false
+		}
 
-	return melodyInstance.BroadcastFilter(msg, func(session *melody.Session) bool {
-		return filterCallback(session.Keys)
+		return true
 	})
 }
 
@@ -316,10 +202,10 @@ func InitWithConcurrentMessageHandling(concurrentMessageHandling bool) InitOptio
 	}
 }
 
-type ConnectionOption func(sessionMap *map[string]any)
+type ConnectionOption func(sessionMap map[string]any)
 
-func WithConnectionContext(context map[string]any) ConnectionOption {
-	return func(sessionMap *map[string]any) {
-		*sessionMap = context
+func WithConnectionContext(context any) ConnectionOption {
+	return func(sessionMap map[string]any) {
+		sessionMap[connectionContextKey] = context
 	}
 }

+ 0 - 0
yaml/yaml_checker/README.md


+ 0 - 0
yaml/yaml_checker/log.go


+ 0 - 0
yaml/yaml_checker/schema.yaml


+ 1 - 1
yaml/yaml_checker/schema_doc.go

@@ -1,7 +1,7 @@
 package yaml_checker
 
 import (
-	"github.com/pkg/errors"
+	"errors"
 	"gopkg.in/yaml.v3"
 	"os"
 )

+ 1 - 1
yaml/yaml_checker/schema_node.go

@@ -1,7 +1,7 @@
 package yaml_checker
 
 import (
-	"github.com/pkg/errors"
+	"errors"
 	"reflect"
 )
 

+ 0 - 0
yaml/yaml_checker/test.yaml


+ 0 - 0
yaml/yaml_checker/utils.go


+ 0 - 0
yaml/yaml_checker/yaml_checker_test.go


+ 0 - 0
yaml/yaml_loader/test.yaml


+ 1 - 1
yaml/yaml_loader/yaml_loader.go

@@ -2,8 +2,8 @@ package yaml_loader
 
 import (
 	"bytes"
+	"errors"
 	"fmt"
-	"github.com/pkg/errors"
 	"gopkg.in/yaml.v3"
 	"io"
 	"os"

+ 0 - 0
yaml/yaml_loader/yaml_loader_test.go