Skip to content

Commit

Permalink
Merge pull request #23 from kei2100/twk-pr-22
Browse files Browse the repository at this point in the history
Tweak #22
  • Loading branch information
kei2100 committed Jul 24, 2022
2 parents 1470ec6 + c460a6f commit bd1007d
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 188 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ message SimpleMessage {

Generate the code
```
protoc -I. -I$(go env GOPATH)/src/github.com/kei2100/protoc-gen-marshal-zap --go_out=. --marshal-zap_out=. simple.proto
PROTOC_GEN_MARSHAL_ZAP_VERSION=v0.1.x # replace latest version
protoc -I. -I$(go env GOMODCACHE)/github.com/kei2100/protoc-gen-marshal-zap@${PROTOC_GEN_MARSHAL_ZAP_VERSION} --go_out=. --marshal-zap_out=. simple.proto
```

Output results should be:
Expand All @@ -47,7 +48,7 @@ simple.pb.marshal-zap.go # auto-generated by protoc-gen-marshal-zap
simple.proto # original proto file
```

`simple_marshal_zap.pb.go` is generated as follows
`simple.pb.marshal-zap.go` is generated as follows

```go
// Code generated by protoc-gen-marshal-zap. DO NOT EDIT.
Expand Down

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

6 changes: 3 additions & 3 deletions plugin/protoc-gen-marshal-zap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func generateMapField(g *protogen.GeneratedFile, f *protogen.Field) {
case protoreflect.StringKind:
g.P("enc.AddString(", g.QualifiedGoIdent(fmtPkg.Ident("Sprintf")), "(\"%v\", k), v)")
default:
g.P("enc.Addlected(", g.QualifiedGoIdent(fmtPkg.Ident("Sprintf")), "(\"%v\", k), v)")
g.P("enc.AddReflected(", g.QualifiedGoIdent(fmtPkg.Ident("Sprintf")), "(\"%v\", k), v)")
}
g.P("}")
g.P("return nil")
Expand Down Expand Up @@ -182,9 +182,9 @@ func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
return nil
}

filename := fmt.Sprintf("%s_marshall_zap.pb.go", file.GeneratedFilenamePrefix)
filename := fmt.Sprintf("%s.pb.marshal-zap.go", file.GeneratedFilenamePrefix)
g := gen.NewGeneratedFile(filename, file.GoImportPath)
g.P("// Code generated by protoc-gen-marshall-zap. DO NOT EDIT.")
g.P("// Code generated by protoc-gen-marshal-zap. DO NOT EDIT.")
g.P("//")
g.P("// source: ", file.Desc.Path())
g.P()
Expand Down
Loading

0 comments on commit bd1007d

Please sign in to comment.