格式化protobuf文件
Go to file
2024-03-19 22:53:48 +08:00
.gitignore first commit 2024-03-19 22:49:04 +08:00
aligned.go first commit 2024-03-19 22:49:04 +08:00
columns.go first commit 2024-03-19 22:49:04 +08:00
extensions.go first commit 2024-03-19 22:49:04 +08:00
formatter_test.go first commit 2024-03-19 22:49:04 +08:00
formatter.go first commit 2024-03-19 22:49:04 +08:00
go.mod first commit 2024-03-19 22:49:04 +08:00
go.sum first commit 2024-03-19 22:49:04 +08:00
inline_comment.go first commit 2024-03-19 22:49:04 +08:00
README.md chore: readme docs 2024-03-19 22:53:48 +08:00
reflector.go first commit 2024-03-19 22:49:04 +08:00
testdata.proto first commit 2024-03-19 22:49:04 +08:00
utils.go first commit 2024-03-19 22:49:04 +08:00

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
	}
}