protoc-gen-go-json
protoc-gen-go-json copied to clipboard
Maintain comments for licenses and build tags
On generated .pb.go files, comments at the beginning of the .proto file are preserved. For example, assume a .proto file that started with:
/*
Copyright © 2020 Alessandro Segala (@ItalyPaleAle)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// +build linux
syntax = "proto3";
package foo;
// < rest of file >
When compiling it and using the json plugin, I get two files.
The .pb.go file preserves the comments, so it starts with:
//
//Copyright © 2020 Alessandro Segala (@ItalyPaleAle)
//
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU Affero General Public License as published
//by the Free Software Foundation, version 3 of the License.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU Affero General Public License for more details.
//
//You should have received a copy of the GNU Affero General Public License
//along with this program. If not, see <https://www.gnu.org/licenses/>.
// +build linux
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.25.0-devel
// protoc v3.13.0
// source: foo.proto
package foo
// < rest of file >
However the .pb.json.go file starts with this only:
// Code generated by protoc-gen-go-json. DO NOT EDIT.
// source: foo.proto
package foo
// < rest of file >
As you can see, there are two important things missing:
- The license
- Optional build tags such as
// +build linux
Better late than never, but I ended up fixing this in https://github.com/mfridman/protoc-gen-go-json/pull/3.