diff --git a/goutils/proto_build/main.go b/goutils/proto_build/main.go index 1c8bde7..d34113b 100644 --- a/goutils/proto_build/main.go +++ b/goutils/proto_build/main.go @@ -54,10 +54,10 @@ func main() { if len(args) == 0 || args[0] == "service" { ServiceMain() - } else if args[0] == "gateway" { - GatewayMain() + } else if args[0] == "client" { + GenClientMain() } else { - log.Println("Invalid argument. Usage: go run main.go [service|gateway]") + log.Println("Invalid argument. Usage: go run main.go [service|client]") } } @@ -104,35 +104,22 @@ go run -gcflags="-N" proto/goutils/proto_build/main.go` // log.Println("Found proto folder at:", workerSpaceDir, ServiceNames, projectLastName, projectName) } -func GatewayMain() { +func GenClientMain() { log.Println("项目目录:", workspaceDir) checkProtoMessageName(workspaceDir + "/" + "proto/service") packageName := "service" - ServerCodePath := "server" + genDir := "gen/go" - ServiceName, projectName, projectLastName := getServiceNameAndProjectName(ServerCodePath) - if ServiceName == "" { - err := os.MkdirAll("server", 0755) - if err != nil { - log.Println(err) - } - createFileWithPermNotExists("server/service_config.ini", func(f io.Writer) error { - return tpl.ExecuteTemplate(f, "service_config.tpl", nil) - }) - panic("必须填写server/service_config.ini文件的项目名称与proto对应名称") - } defer createFileNotExists("protoc.sh", 0755, func(f io.Writer) error { shellstr := `#! /bin/bash -go run -gcflags="-N" proto/goutils/proto_build/main.go gateway` +go run -gcflags="-N" proto/goutils/proto_build/main.go client` f.Write([]byte(shellstr)) return nil }) - // genDir := fmt.Sprintf("gen/go/%s", PackageName) - serviceProtoDir := fmt.Sprintf("proto/%s", packageName) err := os.MkdirAll(genDir+"/"+packageName, 0755) @@ -140,10 +127,16 @@ go run -gcflags="-N" proto/goutils/proto_build/main.go gateway` log.Println(err) } + projectName := "" + projectLastName := "" + ServiceName := "" + + CheckGomodBasicPackage() ExecProtoc(workspaceDir, serviceProtoDir, genDir, packageName, projectName) - ExecCreateAutoGrpc(genDir, packageName) + ExecCreateConfig(ServiceName, projectLastName) - ExecCreateGatewayAutoGrpc(genDir, packageName, projectLastName) + ExecCreateAutoGrpc(genDir, packageName) + ExecCreateAutoLogic(workspaceDir, ServiceName, genDir, packageName, projectLastName) } func ExecCreateConfig(ServiceName, ProjectName string) { diff --git a/goutils/proto_build/main_test.go b/goutils/proto_build/main_test.go index e7727b1..fe7fe53 100644 --- a/goutils/proto_build/main_test.go +++ b/goutils/proto_build/main_test.go @@ -9,5 +9,5 @@ func TestMain(t *testing.T) { } func TestGateway(t *testing.T) { - GatewayMain() + GenClientMain() }