Skip to content

Commit

Permalink
add: 生成的文件尽量保持一致
Browse files Browse the repository at this point in the history
  • Loading branch information
cyz-home committed Nov 8, 2023
1 parent 384309f commit 221a6bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion console/commands/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 23 additions & 2 deletions console/commands/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"os"
"os/exec"
"sort"
"strings"
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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"
Expand Down

0 comments on commit 221a6bc

Please sign in to comment.