diff --git a/go.mod b/go.mod index 575d270..1a863b6 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/spaolacci/murmur3 v1.1.0 github.com/stretchr/testify v1.7.0 github.com/tidwall/gjson v1.9.0 + github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 go.uber.org/zap v1.19.1 gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 73c6950..41770b2 100644 --- a/go.sum +++ b/go.sum @@ -170,6 +170,8 @@ github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/xdg/scram v1.0.3/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= github.com/xdg/stringprep v1.0.3/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= +github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 h1:zzrxE1FKn5ryBNl9eKOeqQ58Y/Qpo3Q9QNxKHX5uzzQ= +github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2/go.mod h1:hzfGeIUDq/j97IG+FhNqkowIyEcD88LrW6fyU3K3WqY= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opentelemetry.io/otel v0.13.0/go.mod h1:dlSNewoRYikTkotEnxdmuBHgzT+k/idJSfDv/FxEnOY= diff --git a/util/string.go b/util/string.go index 0ce9684..da3a050 100644 --- a/util/string.go +++ b/util/string.go @@ -11,6 +11,7 @@ import ( "crypto/md5" "encoding/hex" "math/rand" + "strings" "time" ) @@ -46,3 +47,28 @@ func Md5(str string) string { _, _ = h.Write([]byte(str)) return hex.EncodeToString(h.Sum(nil)) } + +// SnakeCaseToCamel 蛇形字符串转换为驼峰 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 4:58 下午 2021/10/25 +func SnakeCaseToCamel(str string) string { + builder := strings.Builder{} + index := 0 + if str[0] >= 'a' && str[0] <= 'z' { + builder.WriteByte(str[0] - ('a' - 'A')) + index = 1 + } + for i := index; i < len(str); i++ { + if str[i] == '_' && i+1 < len(str) { + if str[i+1] >= 'a' && str[i+1] <= 'z' { + builder.WriteByte(str[i+1] - ('a' - 'A')) + i++ + continue + } + } + builder.WriteByte(str[i]) + } + return builder.String() +}