Skip to content

Commit

Permalink
chore: coding style (#3960)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan authored Mar 2, 2024
1 parent b624b96 commit 25821bd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
26 changes: 13 additions & 13 deletions core/stores/mon/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -48,27 +48,27 @@ 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) {
opts.SetTimeout(timeout)
}
}

// 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)
}
}
6 changes: 3 additions & 3 deletions core/stores/mon/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion tools/goctl/test/integration/model/mongo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21-alpine
FROM golang:1.22-alpine

ENV TZ Asia/Shanghai
ENV GOPROXY https://goproxy.cn,direct
Expand Down

0 comments on commit 25821bd

Please sign in to comment.