Compare commits
No commits in common. "main" and "v0.0.6" have entirely different histories.
25
main.go
25
main.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/format"
|
||||
|
@ -10,7 +9,6 @@ import (
|
|||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"git.apinb.com/bsm-tools/protoc-gen-slc/tpl"
|
||||
|
||||
|
@ -110,13 +108,13 @@ func generateNewServerFile(services []string) error {
|
|||
}
|
||||
|
||||
func generateServerFile(gen *protogen.Plugin, file *protogen.File, service *protogen.Service) error {
|
||||
filename := fmt.Sprintf("./internal/server/%s_server.go", toSnakeCase(service.GoName))
|
||||
filename := fmt.Sprintf("./internal/server/%s_server.go", strings.ToLower(service.GoName))
|
||||
moduleName := getModuleName()
|
||||
|
||||
//create servers.
|
||||
code := tpl.Server
|
||||
imports := []string{
|
||||
"\"" + moduleName + "/internal/logic/" + toSnakeCase(service.GoName) + "\"",
|
||||
"\"" + moduleName + "/internal/logic/" + strings.ToLower(service.GoName) + "\"",
|
||||
"pb \"" + moduleName + "/pb\"",
|
||||
}
|
||||
|
||||
|
@ -149,7 +147,7 @@ func generateServerFile(gen *protogen.Plugin, file *protogen.File, service *prot
|
|||
}
|
||||
|
||||
func generateLogicFile(gen *protogen.Plugin, file *protogen.File, service *protogen.Service) error {
|
||||
logicPath := "./internal/logic/" + toSnakeCase(service.GoName)
|
||||
logicPath := "./internal/logic/" + strings.ToLower(service.GoName)
|
||||
if !utils.PathExists(logicPath) {
|
||||
os.MkdirAll(logicPath, os.ModePerm)
|
||||
}
|
||||
|
@ -287,20 +285,3 @@ func parseOptions(comment string) map[string]string {
|
|||
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -47,6 +47,6 @@ var StatusReplyCode = `
|
|||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue