2 Star 0 Fork 340

hxchjm / go-zero

forked from kevwan / go-zero 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
naming.go 976 Bytes
一键复制 编辑 原始数据 按行查看 历史
kingxt 提交于 2020-11-24 15:11 . feature: file namestyle (#223)
package name
import (
"strings"
"github.com/tal-tech/go-zero/tools/goctl/util/stringx"
)
type NamingStyle = string
const (
NamingLower NamingStyle = "lower"
NamingCamel NamingStyle = "camel"
NamingSnake NamingStyle = "snake"
)
// IsNamingValid validates whether the namingStyle is valid or not,return
// namingStyle and true if it is valid, or else return empty string
// and false, and it is a valid value even namingStyle is empty string
func IsNamingValid(namingStyle string) (NamingStyle, bool) {
if len(namingStyle) == 0 {
namingStyle = NamingLower
}
switch namingStyle {
case NamingLower, NamingCamel, NamingSnake:
return namingStyle, true
default:
return "", false
}
}
func FormatFilename(filename string, style NamingStyle) string {
switch style {
case NamingCamel:
return stringx.From(filename).ToCamel()
case NamingSnake:
return stringx.From(filename).ToSnake()
default:
return strings.ToLower(stringx.From(filename).ToCamel())
}
}
Go
1
https://gitee.com/hxchjm/go-zero.git
git@gitee.com:hxchjm/go-zero.git
hxchjm
go-zero
go-zero
3eb88c4e4bf1

搜索帮助