fix logic name caml
This commit is contained in:
parent
87734c972f
commit
fa9ceaddc6
23
main.go
23
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/format"
|
"go/format"
|
||||||
|
@ -9,6 +10,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"git.apinb.com/bsm-tools/protoc-gen-slc/tpl"
|
"git.apinb.com/bsm-tools/protoc-gen-slc/tpl"
|
||||||
|
|
||||||
|
@ -114,7 +116,7 @@ func generateServerFile(gen *protogen.Plugin, file *protogen.File, service *prot
|
||||||
//create servers.
|
//create servers.
|
||||||
code := tpl.Server
|
code := tpl.Server
|
||||||
imports := []string{
|
imports := []string{
|
||||||
"\"" + moduleName + "/internal/logic/" + strings.ToLower(service.GoName) + "\"",
|
"\"" + moduleName + "/internal/logic/" + toSnakeCase(service.GoName) + "\"",
|
||||||
"pb \"" + moduleName + "/pb\"",
|
"pb \"" + moduleName + "/pb\"",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +149,7 @@ func generateServerFile(gen *protogen.Plugin, file *protogen.File, service *prot
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateLogicFile(gen *protogen.Plugin, file *protogen.File, service *protogen.Service) error {
|
func generateLogicFile(gen *protogen.Plugin, file *protogen.File, service *protogen.Service) error {
|
||||||
logicPath := "./internal/logic/" + strings.ToLower(service.GoName)
|
logicPath := "./internal/logic/" + toSnakeCase(service.GoName)
|
||||||
if !utils.PathExists(logicPath) {
|
if !utils.PathExists(logicPath) {
|
||||||
os.MkdirAll(logicPath, os.ModePerm)
|
os.MkdirAll(logicPath, os.ModePerm)
|
||||||
}
|
}
|
||||||
|
@ -285,3 +287,20 @@ func parseOptions(comment string) map[string]string {
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CamelToSnake 将驼峰命名转换为下划线命名
|
||||||
|
func CamelToSnake(s string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
for i, r := range s {
|
||||||
|
if unicode.IsUpper(r) {
|
||||||
|
// 如果不是第一个字符,添加下划线
|
||||||
|
if i > 0 {
|
||||||
|
buf.WriteRune('_')
|
||||||
|
}
|
||||||
|
buf.WriteRune(unicode.ToLower(r))
|
||||||
|
} else {
|
||||||
|
buf.WriteRune(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue