diff --git a/cmd/errno-gen/command/errno.go b/cmd/errno-gen/command/errno.go index 43c2025..05a2cbc 100644 --- a/cmd/errno-gen/command/errno.go +++ b/cmd/errno-gen/command/errno.go @@ -21,7 +21,7 @@ type Gen struct { Tags []string Version string pkg *Package - ErrorsPkg string + Epk string } func (g *Gen) Generate() error { @@ -94,7 +94,7 @@ func (g *Gen) generateError(typeName string) error { Version: g.Version, IsDeprecated: false, Package: g.pkg.Name, - ErrorsPkg: g.ErrorsPkg, + Epk: g.Epk, Enums: []*Enumerate{ { Type: typeType, diff --git a/cmd/errno-gen/command/errno.tpl b/cmd/errno-gen/command/errno.tpl index b824392..45dcb70 100644 --- a/cmd/errno-gen/command/errno.tpl +++ b/cmd/errno-gen/command/errno.tpl @@ -7,13 +7,12 @@ package {{.Package}} import ( - errors "{{.ErrorsPkg}}" + errors "{{.Epk}}" ) {{- range $e := .Enums}} {{- range $ee := $e.Values}} -// Err{{$ee.OriginalName}} {{.Mapping}} -// `{{$e.TypeName}}`{{$e.Explain}}: {{$ee.Value}} +// Err{{$ee.OriginalName}} {{.Mapping}}({{$ee.Value}} ) func Err{{$ee.OriginalName}}(opts ...errors.Option) error { return errors.New(int32({{$ee.OriginalName}}), {{$ee.OriginalName}}.String(), opts...) } diff --git a/cmd/errno-gen/command/errno_template.go b/cmd/errno-gen/command/errno_template.go index 13ae8ec..370ff8c 100644 --- a/cmd/errno-gen/command/errno_template.go +++ b/cmd/errno-gen/command/errno_template.go @@ -17,7 +17,7 @@ type GenFile struct { Version string IsDeprecated bool Package string - ErrorsPkg string + Epk string Enums []*Enumerate } diff --git a/cmd/errno-gen/command/root.go b/cmd/errno-gen/command/root.go index 942c4a3..66d311c 100644 --- a/cmd/errno-gen/command/root.go +++ b/cmd/errno-gen/command/root.go @@ -16,7 +16,7 @@ type ErrnoOption struct { Type []string Tags []string DisableStringer bool - ErrorsPkg string + Epk string } type RootCmd struct { @@ -77,7 +77,7 @@ func NewRootCmd() *RootCmd { Type: root.Type, Tags: root.Tags, Version: version, - ErrorsPkg: root.ErrorsPkg, + Epk: root.Epk, } err = g.Generate() if err != nil { @@ -100,7 +100,7 @@ func NewRootCmd() *RootCmd { cmd.Flags().StringSliceVarP(&root.Type, "type", "t", nil, "the list type of enum names; must be set") cmd.Flags().StringSliceVar(&root.Tags, "tags", nil, "comma-separated list of build tags to apply") cmd.Flags().BoolVarP(&root.DisableStringer, "disable-stringer", "d", false, "disable use `stringer` command.") - cmd.Flags().StringVarP(&root.ErrorsPkg, "errors-pkg", "e", "github.com/things-go/dyn/errorx", "errors package import path") + cmd.Flags().StringVarP(&root.Epk, "epk", "e", "github.com/things-go/dyn/errorx", "errors package import path") root.cmd = cmd return root diff --git a/cmd/protoc-gen-dyn-errno/errno.tpl b/cmd/protoc-gen-dyn-errno/errno.tpl index 07469ad..f5501b3 100644 --- a/cmd/protoc-gen-dyn-errno/errno.tpl +++ b/cmd/protoc-gen-dyn-errno/errno.tpl @@ -20,6 +20,7 @@ var _ = errors.New {{- range $e := .Errors}} {{$enumName := $e.Name}} {{ range .Values }} +// Err{{.CamelValue}} {{.Message}}({{.Code}}) func Err{{.CamelValue}}(opts ...errors.Option) *errors.Error { return errors.New({{.Code}}, "{{.Message}}", opts...) } diff --git a/example/gen/errno/errno.errno.pb.go b/example/gen/errno/errno.errno.pb.go index 7dcf3a9..493a58c 100644 --- a/example/gen/errno/errno.errno.pb.go +++ b/example/gen/errno/errno.errno.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-dyn-errno. DO NOT EDIT. // versions: // - protoc-gen-dyn-errno v1.0.0 -// - protoc v5.26.1 +// - protoc v5.27.0 // source: errno/errno.proto package errno @@ -13,9 +13,12 @@ import ( // Reference imports to suppress errors if they are not otherwise used. var _ = errors.New +// ErrInternalServer 服务器错误(500) func ErrInternalServer(opts ...errors.Option) *errors.Error { return errors.New(500, "服务器错误", opts...) } + +// ErrTimeout 操作超时(1000) func ErrTimeout(opts ...errors.Option) *errors.Error { return errors.New(1000, "操作超时", opts...) } diff --git a/example/gen/errno/errno.pb.go b/example/gen/errno/errno.pb.go index 5d1edfc..c5e2c14 100644 --- a/example/gen/errno/errno.pb.go +++ b/example/gen/errno/errno.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.33.0 -// protoc v5.26.1 +// protoc-gen-go v1.34.1 +// protoc v5.27.0 // source: errno/errno.proto package errno diff --git a/example/gen/hello/hello.gin.pb.go b/example/gen/hello/hello.gin.pb.go index bab3c94..5545e84 100644 --- a/example/gen/hello/hello.gin.pb.go +++ b/example/gen/hello/hello.gin.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-dyn-gin. DO NOT EDIT. // versions: // - protoc-gen-dyn-gin v1.0.0 -// - protoc v5.26.1 +// - protoc v5.27.0 // source: hello/hello.proto package hello diff --git a/example/gen/hello/hello.pb.go b/example/gen/hello/hello.pb.go index c83afbe..3b53ef0 100644 --- a/example/gen/hello/hello.pb.go +++ b/example/gen/hello/hello.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.33.0 -// protoc v5.26.1 +// protoc-gen-go v1.34.1 +// protoc v5.27.0 // source: hello/hello.proto package hello diff --git a/example/gen/hello/hello.resty.pb.go b/example/gen/hello/hello.resty.pb.go index 2b1bfab..859ba5f 100644 --- a/example/gen/hello/hello.resty.pb.go +++ b/example/gen/hello/hello.resty.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-dyn-resty. DO NOT EDIT. // versions: // - protoc-gen-dyn-resty v1.0.0 -// - protoc v5.26.1 +// - protoc v5.27.0 // source: hello/hello.proto package hello diff --git a/example/gen/hello/hello_grpc.pb.go b/example/gen/hello/hello_grpc.pb.go index cf963f4..b13e0d2 100644 --- a/example/gen/hello/hello_grpc.pb.go +++ b/example/gen/hello/hello_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v5.26.1 +// - protoc v5.27.0 // source: hello/hello.proto package hello diff --git a/example/go.mod b/example/go.mod index eb81709..2466e55 100644 --- a/example/go.mod +++ b/example/go.mod @@ -2,11 +2,11 @@ module github.com/things-go/dyn/example go 1.21 -replace github.com/things-go/dyn v1.0.0-rc1 => ../ +replace github.com/things-go/dyn v1.0.0-rc5 => ../ require ( github.com/gin-gonic/gin v1.10.0 - github.com/things-go/dyn v1.0.0-rc1 + github.com/things-go/dyn v1.0.0-rc5 google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be google.golang.org/grpc v1.64.0 google.golang.org/protobuf v1.34.1 @@ -40,7 +40,7 @@ require ( golang.org/x/crypto v0.23.0 // indirect golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d // indirect golang.org/x/net v0.25.0 // indirect - golang.org/x/oauth2 v0.20.0 // indirect + golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/text v0.15.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240509183442-62759503f434 // indirect diff --git a/example/go.sum b/example/go.sum index 1a56fcf..42e485a 100644 --- a/example/go.sum +++ b/example/go.sum @@ -101,8 +101,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= -golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= +golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=