修改自动grpc不需要在项目配置

This commit is contained in:
huangsimin@fusen.cn 2023-12-13 17:08:50 +08:00
parent 702248cc8f
commit ac925c3424
2 changed files with 33 additions and 5 deletions

View File

@ -127,16 +127,13 @@ go run -gcflags="-N" proto/goutils/proto_build/main.go client`
log.Println(err)
}
projectName := ""
projectLastName := ""
ServiceName := ""
projectName := "gitlab.fusenpack.com/backend/grpc"
CheckGomodBasicPackage()
ExecProtoc(workspaceDir, serviceProtoDir, genDir, packageName, projectName)
GitignoreGenCheck()
ExecCreateConfig(ServiceName, projectLastName)
ExecCreateAutoGrpc(genDir, packageName)
ExecCreateAutoLogic(workspaceDir, ServiceName, genDir, packageName, projectLastName)
}
func ExecCreateConfig(ServiceName, ProjectName string) {
@ -887,6 +884,7 @@ func importFileCmdStr(importFile string, projectName string) string {
log.Printf("模板执行失败:%v\n", err)
return ""
}
// log.Println(buf.String())
return buf.String()
}
@ -1531,3 +1529,28 @@ func getGrpcFileServiceName(decl ast.Decl) (string, string, bool) {
}
return "", "", false
}
// 检测gitignore gen是否存在
func GitignoreGenCheck() {
gitignoreFile := "./.gitignore"
data, err := os.ReadFile(gitignoreFile)
if err != nil {
log.Println(err.Error())
return
}
for _, line := range strings.Split(string(data), "\n") {
if strings.Trim(line, " ") == "gen" {
return
}
}
data = append(data, []byte("\ngen\n")...)
err = os.WriteFile(gitignoreFile, data, 0644)
if err != nil {
panic(err)
}
}

View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"reflect"
"fusen-basic/env"
"github.com/nacos-group/nacos-sdk-go/v2/clients/naming_client"
"github.com/nacos-group/nacos-sdk-go/v2/vo"
@ -14,6 +15,10 @@ import (
var namingClient naming_client.INamingClient
var groupName string
func init() {
AutoGrpcInit(env.StartAutoGrpc())
}
// AutoGrpcInit auto grpc 必须调用初始化
func AutoGrpcInit(obj any) {
value := reflect.ValueOf(obj)