From 221a6bc0292f57f6924e83cfd9bad3ab2376ee36 Mon Sep 17 00:00:00 2001 From: yuanzhao <2206582181@qq.com> Date: Wed, 8 Nov 2023 15:11:40 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E7=94=9F=E6=88=90=E7=9A=84=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=B0=BD=E9=87=8F=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- console/commands/bean.go | 9 ++++++++- console/commands/route.go | 25 +++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index fb9547b..41f0190 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ ATDIR := $(shell pwd) # mac 系统更新path可能不全 export PATH := $(GOBIN):$(PATH) -build: +build-mac: go build -ldflags="-w -s" -o $(GOBIN)/toolset ./ build-win: diff --git a/console/commands/bean.go b/console/commands/bean.go index 4294156..51e0c22 100644 --- a/console/commands/bean.go +++ b/console/commands/bean.go @@ -83,7 +83,14 @@ func (BeanCommand) Execute(input command.Input) { bc := newBeanCache() for _, fileParser := range fileParsers { bc.name = fileParser.PackageName - for _, goType := range fileParser.Types { + keys := make([]string, 0) + for k := range fileParser.Types { + keys = append(keys, k) + } + sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] }) + // 排序后循环 type + for _, k := range keys { + goType := fileParser.Types[k] for _, attr := range goType.Attrs { if attr.HasTag("inject") { // 只收集使用到的 import diff --git a/console/commands/route.go b/console/commands/route.go index 1194ff5..35cae0b 100644 --- a/console/commands/route.go +++ b/console/commands/route.go @@ -8,6 +8,7 @@ import ( "log" "os" "os/exec" + "sort" "strings" ) @@ -453,14 +454,16 @@ func genRoutesFunc(g *ApiGroups, m map[string]string) string { "\n\treturn map[*" + homeApi + ".Config]func(c *" + homeGin + ".Context){" for _, server := range g.servers { - for s, v := range server.Opt { + for _, s := range forOpt(server.Opt) { + v := server.Opt[s] if s == "http.Resource" { str += "\n\t\t" + homeApi + ".Get(\"" + v.Val + "\"):" + "c." + parser.StringToSnake(server.Name) + ".GinHandleCurd," str += "\n\t\t" + homeApi + ".Post(\"" + v.Val + "\"):" + "c." + parser.StringToSnake(server.Name) + ".GinHandleCurd," str += "\n\t\t" + homeApi + ".Any(\"" + v.Val + "/:action\"):" + "c." + parser.StringToSnake(server.Name) + ".GinHandleCurd," } } - for rName, rpc := range server.Rpc { + for _, rName := range forServerOpt(server.Rpc) { + rpc := server.Rpc[rName] for _, options := range rpc.Opt { for _, option := range options { if strings.Index(option.Key, "http.") == 0 { @@ -477,6 +480,24 @@ func genRoutesFunc(g *ApiGroups, m map[string]string) string { return str + "\n\t}\n}" } +func forServerOpt(m map[string]parser.ServiceRpc) []string { + keys := make([]string, 0) + for k := range m { + keys = append(keys, k) + } + sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] }) + return keys +} + +func forOpt(m map[string]parser.Option) []string { + keys := make([]string, 0) + for k := range m { + keys = append(keys, k) + } + sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] }) + return keys +} + func genRoutesStruct(g *ApiGroups, m map[string]string) string { str := "\n// @Bean" + "\ntype " + parser.StringToHump(g.name) + "Routes struct {\n"