Skip to content

Commit

Permalink
fix: fix tempalte
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Jun 5, 2024
1 parent fcefa0a commit 62e63a5
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cmd/errno-gen/command/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Gen struct {
Tags []string
Version string
pkg *Package
ErrorsPkg string
Epk string
}

func (g *Gen) Generate() error {
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions cmd/errno-gen/command/errno.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/errno-gen/command/errno_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type GenFile struct {
Version string
IsDeprecated bool
Package string
ErrorsPkg string
Epk string
Enums []*Enumerate
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/errno-gen/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ErrnoOption struct {
Type []string
Tags []string
DisableStringer bool
ErrorsPkg string
Epk string
}

type RootCmd struct {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/protoc-gen-dyn-errno/errno.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand Down
5 changes: 4 additions & 1 deletion example/gen/errno/errno.errno.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/gen/errno/errno.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/gen/hello/hello.gin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/gen/hello/hello.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/gen/hello/hello.resty.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/gen/hello/hello_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions example/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 62e63a5

Please sign in to comment.