Skip to content

Commit

Permalink
Merge pull request #101 from suyuan32/dev
Browse files Browse the repository at this point in the history
fix: sort rpc proto data
  • Loading branch information
suyuan32 authored Jun 2, 2024
2 parents 1c0d452 + 0f14f96 commit fa683d9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var OldGoZeroVersion = []string{"v1.5.6", "v1.6.0", "v1.6.1", "v1.6.2", "v1.6.3"
const DefaultToolVersion = "v1.6.11"

// GoctlsVersion is goctls version
const GoctlsVersion = "v1.7.3"
const GoctlsVersion = "v1.7.4"

// CoreVersion is the core service version.
const CoreVersion = "v1.4.3"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20221230185412-738e83a70c30 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
Expand Down
18 changes: 9 additions & 9 deletions rpc/generator/proto/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,20 @@ func parseProto(data []parser.Proto) parser.Proto {

}

for _, v := range importSet {
result.Import = append(result.Import, v)
for _, v := range SortImport(importSet) {
result.Import = append(result.Import, importSet[v])
}

for _, e := range enumSet {
result.Enum = append(result.Enum, e)
for _, e := range SortEnum(enumSet) {
result.Enum = append(result.Enum, enumSet[e])
}

for _, m := range messageSet {
result.Message = append(result.Message, m)
for _, m := range SortMessage(messageSet) {
result.Message = append(result.Message, messageSet[m])
}

for _, s := range serviceSet {
result.Service = append(result.Service, s)
for _, s := range SortService(serviceSet) {
result.Service = append(result.Service, serviceSet[s])
}

return result
Expand All @@ -148,7 +148,7 @@ func genProtoString(data parser.Proto) string {

protoString.WriteString("syntax = \"proto3\";\n\n")
protoString.WriteString(fmt.Sprintf("package %s;\n", data.Package.Name))
protoString.WriteString(fmt.Sprintf("option go_package=\"%s\";\n\n", data.GoPackage))
protoString.WriteString(fmt.Sprintf("option go_package = \"%s\";\n\n", data.GoPackage))

for _, i := range data.Import {
protoString.WriteString(fmt.Sprintf("import \"%s\";\n\n", i.Filename))
Expand Down
50 changes: 50 additions & 0 deletions rpc/generator/proto/sort.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package proto

import (
"github.com/duke-git/lancet/v2/slice"
"github.com/suyuan32/goctls/rpc/parser"
)

func SortImport(data map[string]parser.Import) (result []string) {
result = []string{}
for k, _ := range data {
result = append(result, k)
}

slice.Sort(result)

return result
}

func SortEnum(data map[string]parser.Enum) (result []string) {
result = []string{}
for k, _ := range data {
result = append(result, k)
}

slice.Sort(result)

return result
}

func SortMessage(data map[string]parser.Message) (result []string) {
result = []string{}
for k, _ := range data {
result = append(result, k)
}

slice.Sort(result)

return result
}

func SortService(data map[string]parser.Service) (result []string) {
result = []string{}
for k, _ := range data {
result = append(result, k)
}

slice.Sort(result)

return result
}

0 comments on commit fa683d9

Please sign in to comment.