fix mod
This commit is contained in:
61
main.go
61
main.go
@@ -7,10 +7,11 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"protoc-gen-slc/tpl"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"git.apinb.com/bsm-tools/protoc-gen-slc/tpl"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"golang.org/x/mod/modfile"
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
@@ -145,12 +146,6 @@ func generateServerFile(gen *protogen.Plugin, file *protogen.File, service *prot
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateClientFile(gen *protogen.Plugin, file *protogen.File, service *protogen.Service) error {
|
||||
filename := fmt.Sprintf("%s_client.pb.go", strings.ToLower(service.GoName))
|
||||
fmt.Println(filename, file.GoImportPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateLogicFile(gen *protogen.Plugin, file *protogen.File, service *protogen.Service) error {
|
||||
logicPath := "./internal/logic/" + strings.ToLower(service.GoName)
|
||||
if !utils.PathExists(logicPath) {
|
||||
@@ -169,6 +164,26 @@ func generateLogicFile(gen *protogen.Plugin, file *protogen.File, service *proto
|
||||
"pb \"" + moduleName + "/pb\"",
|
||||
}
|
||||
|
||||
if strings.ToLower(method.Input.GoIdent.GoName) == "identrequest" || strings.ToLower(method.Input.GoIdent.GoName) == "fetchrequest" {
|
||||
if strings.ToLower(method.Input.GoIdent.GoName) == "identrequest" {
|
||||
imports = append(imports, "\"git.apinb.com/bsm-sdk/core/errcode\"")
|
||||
code = strings.ReplaceAll(code, "{valid}", tpl.ValidCode)
|
||||
}
|
||||
if strings.ToLower(method.Input.GoIdent.GoName) == "fetchrequest" {
|
||||
code = strings.ReplaceAll(code, "{valid}", tpl.FetchValidCode)
|
||||
}
|
||||
|
||||
} else {
|
||||
code = strings.ReplaceAll(code, "{valid}", "// TODO: valid code")
|
||||
}
|
||||
|
||||
if strings.ToLower(method.Output.GoIdent.GoName) == "statusreply" {
|
||||
imports = append(imports, "\"time\"")
|
||||
code = strings.ReplaceAll(code, "{return}", tpl.StatusReplyCode)
|
||||
} else {
|
||||
code = strings.ReplaceAll(code, "{return}", "return ")
|
||||
}
|
||||
|
||||
code = strings.ReplaceAll(code, "{import}", strings.Join(imports, "\n"))
|
||||
commit := strings.TrimSpace(method.Comments.Leading.String())
|
||||
code = strings.ReplaceAll(code, "{func}", method.GoName)
|
||||
@@ -176,13 +191,12 @@ func generateLogicFile(gen *protogen.Plugin, file *protogen.File, service *proto
|
||||
code = strings.ReplaceAll(code, "{input}", method.Input.GoIdent.GoName)
|
||||
code = strings.ReplaceAll(code, "{output}", method.Output.GoIdent.GoName)
|
||||
|
||||
// formattedCode, err := format.Source([]byte(code))
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("failed to format generated code: %w", err)
|
||||
// }
|
||||
formattedCode, err := format.Source([]byte(code))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to format generated code: %w", err)
|
||||
}
|
||||
|
||||
// StringToFile(filename, string(formattedCode))
|
||||
StringToFile(filename, code)
|
||||
StringToFile(filename, string(formattedCode))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -250,3 +264,24 @@ func StringToFile(path, content string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// parseOptions 解析注释中的选项字符串并返回一个 map
|
||||
func parseOptions(comment string) map[string]string {
|
||||
// 去掉注释符号和分号
|
||||
comment = strings.Trim(comment, " //;")
|
||||
// 按逗号分割选项
|
||||
options := strings.Split(comment, ",")
|
||||
result := make(map[string]string)
|
||||
|
||||
for _, opt := range options {
|
||||
// 按等号分割键和值
|
||||
parts := strings.SplitN(opt, "=", 2)
|
||||
if len(parts) == 2 {
|
||||
key := strings.TrimSpace(parts[0])
|
||||
value := strings.TrimSpace(parts[1])
|
||||
result[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user