golang protobuf remove omitempty tag from generated json tags

后端 未结 7 1288
余生分开走
余生分开走 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:44

    A [more] portable solution:

    Use sed to strip the tags after generating via protoc.

    Example of what I actually use in my go:generate script after having generated the *.pb.go files:

    ls *.pb.go | xargs -n1 -IX bash -c 'sed s/,omitempty// X > X.tmp && mv X{.tmp,}'
    

    Note: sed -i (inline-replacement) is not used here because that flag isn't portable between standard OS-X and Linux.

提交回复
热议问题