From e7bf608552dd6e8c886a69bf48bd06cad1117383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Tue, 22 Nov 2022 16:45:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BAAPI=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=97=B6=E5=AF=B9=E6=95=B0=E6=8D=AE=E8=BF=9B=E8=A1=8C=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=EF=BC=8C=E4=BB=A5=E4=BF=9D=E8=AF=81=E6=AF=8F=E6=AC=A1?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E7=9A=84=E7=A8=B3=E5=AE=9A=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/proto-json/main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmd/proto-json/main.go b/cmd/proto-json/main.go index 051bab6..002e226 100644 --- a/cmd/proto-json/main.go +++ b/cmd/proto-json/main.go @@ -14,6 +14,7 @@ import ( "os" "path/filepath" "regexp" + "sort" "strings" ) @@ -111,6 +112,9 @@ func main() { } } + // 排序以保证输出内容的稳定性 + sort.Strings(rootDirs) + for _, rootDir := range rootDirs { files, err := filepath.Glob(rootDir + "/service_*.go") if err != nil { @@ -118,6 +122,9 @@ func main() { return } + // 排序以保证输出内容的稳定性 + sort.Strings(files) + var methodNameReg = regexp.MustCompile(`func\s*\(\w+\s+\*\s*(\w+Service)\)\s*(\w+)\s*\(`) // $1: serviceName, $2 methodName for _, file := range files { data, err := os.ReadFile(file) @@ -234,6 +241,9 @@ func main() { return } + // 排序以保持稳定性 + sort.Strings(files) + for _, path := range files { func(path string) { var filename = filepath.Base(path) @@ -385,6 +395,9 @@ func main() { return } + // 排序以保持稳定性 + sort.Strings(files) + for _, path := range files { func(path string) { var name = strings.TrimSuffix(filepath.Base(path), ".md") @@ -404,6 +417,11 @@ func main() { } } + // 对消息进行排序,以保持稳定性 + sort.Slice(messages, func(i, j int) bool { + return messages[i].Name < messages[j].Name + }) + var rpcList = &RPCList{ Services: services, Messages: messages,