From 7dd8cf766dfbe33cb4f58b1db4c47436a259a31f Mon Sep 17 00:00:00 2001 From: helei Date: Tue, 12 May 2026 11:12:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20AnyArray=20?= =?UTF-8?q?=E7=9A=84=E5=86=97=E4=BD=99=20JSON=20=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除手动实现的 MarshalJSON/UnmarshalJSON 方法,使用 goccy/go-json 的默认泛型实现,同时更新依赖版本 Co-Authored-By: Claude Opus 4.7 (1M context) --- dataType/array.go | 24 -------------- go.mod | 79 ++++++++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 63 deletions(-) diff --git a/dataType/array.go b/dataType/array.go index 0ed3fb1..9af541d 100644 --- a/dataType/array.go +++ b/dataType/array.go @@ -1,10 +1,8 @@ package dataType import ( - "bytes" "context" "database/sql/driver" - "encoding/json" "fmt" "gorm.io/gorm" @@ -35,28 +33,6 @@ func (a AnyArray[T]) GormValue(ctx context.Context, db *gorm.DB) clause.Expr { return arrayGormValue(a, db) } -func (a AnyArray[T]) MarshalJSON() ([]byte, error) { - if a == nil { - return []byte("null"), nil - } - return json.Marshal(a) -} - -func (a *AnyArray[T]) UnmarshalJSON(b []byte) error { - // 处理 null - if bytes.Equal(b, []byte("null")) { - *a = nil - return nil - } - - var tmp []T - if err := json.Unmarshal(b, &tmp); err != nil { - return err - } - *a = tmp - return nil -} - // ToSlice 转换为普通切片 func (a AnyArray[T]) ToSlice() []T { return []T(a) diff --git a/go.mod b/go.mod index c0daa51..6f686c6 100644 --- a/go.mod +++ b/go.mod @@ -3,48 +3,48 @@ module helay.net/go/utils/v3 go 1.25.0 require ( - github.com/IBM/sarama v1.47.0 + github.com/IBM/sarama v1.48.0 github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de github.com/cespare/xxhash/v2 v2.3.0 github.com/colinmarc/hdfs/v2 v2.4.0 github.com/dchest/captcha v1.1.0 - github.com/elastic/go-elasticsearch/v8 v8.19.3 + github.com/elastic/go-elasticsearch/v8 v8.19.5 github.com/gin-gonic/gin v1.12.0 github.com/go-playground/form/v4 v4.3.0 - github.com/go-sql-driver/mysql v1.9.3 + github.com/go-sql-driver/mysql v1.10.0 github.com/go-stomp/stomp/v3 v3.1.5 github.com/go-zookeeper/zk v1.0.4 - github.com/goccy/go-json v0.10.5 + github.com/goccy/go-json v0.10.6 github.com/golang-jwt/jwt/v5 v5.3.1 github.com/gomodule/redigo v1.9.3 github.com/google/uuid v1.6.0 github.com/gorilla/handlers v1.5.2 github.com/gorilla/schema v1.4.1 github.com/helays/gomail/v2 v2.0.3 - github.com/jackc/pgx/v5 v5.8.0 + github.com/jackc/pgx/v5 v5.9.2 github.com/jlaffaye/ftp v0.2.0 github.com/malfunkt/iprange v0.9.0 - github.com/minio/minio-go/v7 v7.0.98 + github.com/minio/minio-go/v7 v7.1.0 github.com/nacos-group/nacos-sdk-go/v2 v2.3.5 github.com/natefinch/lumberjack v2.0.0+incompatible github.com/pkg/errors v0.9.1 github.com/pkg/sftp v1.13.10 github.com/quic-go/quic-go v0.59.0 github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9 - github.com/redis/go-redis/v9 v9.18.0 + github.com/redis/go-redis/v9 v9.19.0 github.com/robfig/cron/v3 v3.0.1 github.com/sony/sonyflake/v2 v2.2.0 github.com/tjfoc/gmsm v1.4.1 github.com/vmihailenco/msgpack/v5 v5.4.1 github.com/xdg-go/scram v1.2.0 github.com/xuri/excelize/v2 v2.10.1 - go.etcd.io/etcd/client/v3 v3.6.8 - go.uber.org/zap v1.27.1 + go.etcd.io/etcd/client/v3 v3.6.10 + go.uber.org/zap v1.28.0 go4.org/netipx v0.0.0-20231129151722-fdeea329fbba - golang.org/x/crypto v0.48.0 - golang.org/x/exp v0.0.0-20260218203240-3dfff04db8fa - golang.org/x/net v0.51.0 - golang.org/x/text v0.34.0 + golang.org/x/crypto v0.50.0 + golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f + golang.org/x/net v0.53.0 + golang.org/x/text v0.36.0 gopkg.in/ini.v1 v1.67.1 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 gopkg.in/yaml.v3 v3.0.1 @@ -78,11 +78,11 @@ require ( github.com/aliyun/credentials-go v1.4.11 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/buger/jsonparser v1.1.1 // indirect - github.com/bytedance/gopkg v0.1.3 // indirect - github.com/bytedance/sonic v1.15.0 // indirect - github.com/bytedance/sonic/loader v0.5.0 // indirect + github.com/bytedance/gopkg v0.1.4 // indirect + github.com/bytedance/sonic v1.15.1 // indirect + github.com/bytedance/sonic/loader v0.5.1 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect - github.com/cloudwego/base64x v0.1.6 // indirect + github.com/cloudwego/base64x v0.1.7 // indirect github.com/coreos/go-semver v0.3.1 // indirect github.com/coreos/go-systemd/v22 v22.7.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect @@ -91,21 +91,21 @@ require ( github.com/dustin/go-humanize v1.0.1 // indirect github.com/eapache/go-resiliency v1.7.0 // indirect github.com/eapache/queue v1.1.0 // indirect - github.com/elastic/elastic-transport-go/v8 v8.9.0 // indirect + github.com/elastic/elastic-transport-go/v8 v8.11.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/gabriel-vasile/mimetype v1.4.13 // indirect - github.com/gin-contrib/sse v1.1.0 // indirect + github.com/gin-contrib/sse v1.1.1 // indirect github.com/go-ini/ini v1.67.0 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.30.1 // indirect + github.com/go-playground/validator/v10 v10.30.2 // indirect github.com/goccy/go-yaml v1.19.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/mock v1.7.0-rc.1 // indirect github.com/golang/protobuf v1.5.4 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect @@ -122,13 +122,13 @@ require ( github.com/jinzhu/now v1.1.5 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/compress v1.18.4 // indirect + github.com/klauspost/compress v1.18.5 // indirect github.com/klauspost/cpuid/v2 v2.3.0 // indirect github.com/klauspost/crc32 v1.3.0 // indirect github.com/kr/fs v0.1.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-sqlite3 v1.14.34 // indirect + github.com/mattn/go-isatty v0.0.22 // indirect + github.com/mattn/go-sqlite3 v1.14.44 // indirect github.com/minio/crc64nvme v1.1.1 // indirect github.com/minio/md5-simd v1.1.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -136,9 +136,9 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect github.com/orcaman/concurrent-map v1.0.0 // indirect - github.com/pelletier/go-toml/v2 v2.2.4 // indirect + github.com/pelletier/go-toml/v2 v2.3.0 // indirect github.com/philhofer/fwd v1.2.0 // indirect - github.com/pierrec/lz4/v4 v4.1.25 // indirect + github.com/pierrec/lz4/v4 v4.1.26 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.23.2 // indirect github.com/prometheus/client_model v0.6.2 // indirect @@ -149,7 +149,7 @@ require ( github.com/richardlehane/msoleps v1.0.6 // indirect github.com/rs/xid v1.6.0 // indirect github.com/tiendc/go-deepcopy v1.7.2 // indirect - github.com/tinylib/msgp v1.6.3 // indirect + github.com/tinylib/msgp v1.6.4 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.3.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect @@ -157,25 +157,26 @@ require ( github.com/xdg-go/stringprep v1.0.4 // indirect github.com/xuri/efp v0.0.1 // indirect github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 // indirect - go.etcd.io/etcd/api/v3 v3.6.8 // indirect - go.etcd.io/etcd/client/pkg/v3 v3.6.8 // indirect - go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect + github.com/zeebo/xxh3 v1.1.0 // indirect + go.etcd.io/etcd/api/v3 v3.6.10 // indirect + go.etcd.io/etcd/client/pkg/v3 v3.6.10 // indirect + go.mongodb.org/mongo-driver/v2 v2.6.0 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect - go.opentelemetry.io/otel v1.41.0 // indirect - go.opentelemetry.io/otel/metric v1.41.0 // indirect - go.opentelemetry.io/otel/trace v1.41.0 // indirect + go.opentelemetry.io/otel v1.43.0 // indirect + go.opentelemetry.io/otel/metric v1.43.0 // indirect + go.opentelemetry.io/otel/trace v1.43.0 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.yaml.in/yaml/v2 v2.4.3 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect - golang.org/x/arch v0.24.0 // indirect - golang.org/x/sync v0.19.0 // indirect - golang.org/x/sys v0.41.0 // indirect + golang.org/x/arch v0.26.0 // indirect + golang.org/x/sync v0.20.0 // indirect + golang.org/x/sys v0.43.0 // indirect golang.org/x/time v0.14.0 // indirect google.golang.org/genproto v0.0.0-20260226221140-a57be14db171 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 // indirect - google.golang.org/grpc v1.79.1 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20260427160629-7cedc36a6bc4 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4 // indirect + google.golang.org/grpc v1.80.0 // indirect google.golang.org/protobuf v1.36.11 // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect