chore: readme docs
This commit is contained in:
parent
993f06cb18
commit
8b979a653d
36
README.md
Normal file
36
README.md
Normal file
@ -0,0 +1,36 @@
|
||||
# protofmt
|
||||
|
||||
修改自 [https://github.com/emicklei/proto-contrib](https://github.com/emicklei/proto-contrib)
|
||||
|
||||
## 使用
|
||||
|
||||
```go
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
```
|
Loading…
Reference in New Issue
Block a user