Search code examples
protocol-buffersprotoc

Preserve //go:generate comment in protobuf files


I want to do some code generations on code generated by protoc through go:generate. However, when it was compiled by protoc, comments are reformed into // go:generate, where a space was inserted, which fails go generate.

Is there a way to preserve comments(do it properly) as it is in protoc?


Solution

  • I finally end up with using bash to replace them.

    for filename in ./pkg/rpc/*.go; do
        sed -i "s#// go:generate#//go:generate#g" $filename
    done