Repository: zeromicro/go-zero
Pull request #3960 (2024-03-02 15:28:10)

chore: coding style

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/zeromicro/go-zero/pull/3960?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 94.70%. Comparing base [(`be7f939`)](https://app.codecov.io/gh/zeromicro/go-zero/commit/be7f93924a5195e64bb944d569e8e6e0aa4483f0?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro) to head [(`a6b1024`)](https://app.codecov.io/gh/zeromicro/go-zero/pull/3960?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro).

<details><summary>Additional details and impacted files</summary>



| [Files](https://app.codecov.io/gh/zeromicro/go-zero/pull/3960?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro) | Coverage Δ | |
|---|---|---|
| [core/stores/mon/options.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/3960?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro#diff-Y29yZS9zdG9yZXMvbW9uL29wdGlvbnMuZ28=) | `100.00% <100.00%> (ø)` | |

... and [1 file with indirect coverage changes](https://app.codecov.io/gh/zeromicro/go-zero/pull/3960/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro)

</details>

Patch:
diff --git a/core/stores/mon/options.go b/core/stores/mon/options.go
index 14a6666a..cebae6f7 100644
--- a/core/stores/mon/options.go
+++ b/core/stores/mon/options.go
@@ -19,17 +19,17 @@ var (
 )
 
 type (
-	options = mopt.ClientOptions
-
 	// Option defines the method to customize a mongo model.
 	Option func(opts *options)
 
-	// RegisterType A struct store With custom type and Encoder/Decoder
-	RegisterType struct {
+	// TypeCodec is a struct that stores specific type Encoder/Decoder.
+	TypeCodec struct {
 		ValueType reflect.Type
 		Encoder   bsoncodec.ValueEncoder
 		Decoder   bsoncodec.ValueDecoder
 	}
+
+	options = mopt.ClientOptions
 )
 
 // DisableLog disables logging of mongo commands, includes info and slow logs.
@@ -48,12 +48,6 @@ func SetSlowThreshold(threshold time.Duration) {
 	slowThreshold.Set(threshold)
 }
 
-func defaultTimeoutOption() Option {
-	return func(opts *options) {
-		opts.SetTimeout(defaultTimeout)
-	}
-}
-
 // WithTimeout set the mon client operation timeout.
 func WithTimeout(timeout time.Duration) Option {
 	return func(opts *options) {
@@ -61,14 +55,20 @@ func WithTimeout(timeout time.Duration) Option {
 	}
 }
 
-// WithRegistry set the Registry to convert custom type to mongo primitive type more easily.
-func WithRegistry(registerType ...RegisterType) Option {
+// WithTypeCodec registers TypeCodecs to convert custom types.
+func WithTypeCodec(typeCodecs ...TypeCodec) Option {
 	return func(opts *options) {
 		registry := bson.NewRegistry()
-		for _, v := range registerType {
+		for _, v := range typeCodecs {
 			registry.RegisterTypeEncoder(v.ValueType, v.Encoder)
 			registry.RegisterTypeDecoder(v.ValueType, v.Decoder)
 		}
 		opts.SetRegistry(registry)
 	}
 }
+
+func defaultTimeoutOption() Option {
+	return func(opts *options) {
+		opts.SetTimeout(defaultTimeout)
+	}
+}
diff --git a/tools/goctl/Dockerfile b/tools/goctl/Dockerfile
index 10eb9e1d..12489e28 100644
--- a/tools/goctl/Dockerfile
+++ b/tools/goctl/Dockerfile
@@ -35,6 +35,6 @@ LABEL org.opencontainers.image.description="A cloud-native Go microservices fram
 LABEL org.opencontainers.image.licenses="MIT"
 LABEL org.opencontainers.image.source="https://github.com/zeromicro/go-zero"
 LABEL org.opencontainers.image.title="goctl (cli)"
-LABEL org.opencontainers.image.version="v1.6.0"
+LABEL org.opencontainers.image.version="v1.6.2"
 
 ENTRYPOINT ["/usr/local/bin/goctl"]


Test patch:
diff --git a/core/stores/mon/options_test.go b/core/stores/mon/options_test.go
index f5a858ad..48024dbd 100644
--- a/core/stores/mon/options_test.go
+++ b/core/stores/mon/options_test.go
@@ -79,16 +79,16 @@ func TestWithRegistryForTimestampRegisterType(t *testing.T) {
 		return nil
 	}
 
-	registerType := []RegisterType{
+	codecs := []TypeCodec{
 		{
 			ValueType: reflect.TypeOf(time.Time{}),
 			Encoder:   mongoDateTimeEncoder,
 			Decoder:   mongoDateTimeDecoder,
 		},
 	}
-	WithRegistry(registerType...)(opts)
+	WithTypeCodec(codecs...)(opts)
 
-	for _, v := range registerType {
+	for _, v := range codecs {
 		// Validate Encoder
 		enc, err := opts.Registry.LookupEncoder(v.ValueType)
 		if err != nil {
diff --git a/tools/goctl/test/integration/model/mongo/Dockerfile b/tools/goctl/test/integration/model/mongo/Dockerfile
index 8d8a2ac9..fe629b13 100644
--- a/tools/goctl/test/integration/model/mongo/Dockerfile
+++ b/tools/goctl/test/integration/model/mongo/Dockerfile
@@ -1,4 +1,4 @@
-FROM golang:1.21-alpine
+FROM golang:1.22-alpine
 
 ENV TZ Asia/Shanghai
 ENV GOPROXY https://goproxy.cn,direct