golang protobuf remove omitempty tag from generated json tags

后端 未结 7 1323
余生分开走
余生分开走 2021-02-04 00:00

I am using google grpc with a json proxy. for some reason i need to remove the omitempty tags from the struct generated in the *.pb.go files.

if i have a pr

7条回答
  •  梦谈多话
    2021-02-04 00:24

    I found that the omitempty json tag is hard-coded into the protoc-gen-go source around line 1778:

    tag := fmt.Sprintf("protobuf:%s json:%q",
        g.goTag(message, field, wiretype), jsonName+",omitempty")
    

    it will be easy changing the source and make a new protoc-gen-go binary yourself.

    It's worth noting that this is likely inadvisable and not recommended for several reasons, particularly because you will then be responsible for ensuring that the hacked up binary always gets used if the protobufs need to be regenerated.

提交回复
热议问题