Skip to content

Commit

Permalink
feat: fixed service and func order
Browse files Browse the repository at this point in the history
  • Loading branch information
sorcererxw committed Sep 29, 2021
1 parent 84d9d82 commit 64c56be
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 66 deletions.
2 changes: 1 addition & 1 deletion example/another.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/petstore.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 64 additions & 64 deletions example/petstore_grpc_mock.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
_ "embed"
"fmt"
pathpkg "path"
"sort"
"text/template"

"google.golang.org/protobuf/compiler/protogen"
Expand Down Expand Up @@ -62,6 +63,23 @@ func parseFile(path string, file *protogen.File) (data Data) {
for k, v := range imports {
data.Imports = append(data.Imports, fmt.Sprintf(`%s "%s"`, v, k))
}

return orderData(data)
}

func orderData(data Data) Data {
services := data.Services
sort.Slice(services, func(i, j int) bool {
return services[i].Service < services[j].Service
})
for k := range services {
funcs := services[k].Funcs
sort.Slice(funcs, func(i, j int) bool {
return funcs[i].Func < funcs[j].Func
})
services[k].Funcs = funcs
}
data.Services = services
return data
}

Expand Down

0 comments on commit 64c56be

Please sign in to comment.