格式化protobuf文件
.gitignore | ||
aligned.go | ||
columns.go | ||
extensions.go | ||
formatter_test.go | ||
formatter.go | ||
go.mod | ||
go.sum | ||
inline_comment.go | ||
README.md | ||
reflector.go | ||
testdata.proto | ||
utils.go |
protofmt
修改自 https://github.com/emicklei/proto-contrib
使用
package main
import (
"bytes"
"os"
"github.com/emicklei/proto"
"gitter.top/common/protofmt"
)
func main() {
def, err := os.ReadFile("testdata.proto")
if err != nil {
// do something
}
parser := proto.NewParser(bytes.NewReader(def))
parse, err := parser.Parse()
if err != nil {
// do something
}
var buf = new(bytes.Buffer)
protofmt.NewFormatter(buf, " ").Format(parse)
err = os.WriteFile("testdata.proto", buf.Bytes(), os.ModePerm)
if err != nil {
// do something
}
}