diff --git a/tools/goctl/model/sql/gen/delete.go b/tools/goctl/model/sql/gen/delete.go index c62eb31a..a14c3171 100644 --- a/tools/goctl/model/sql/gen/delete.go +++ b/tools/goctl/model/sql/gen/delete.go @@ -33,7 +33,7 @@ func genDelete(table Table, withCache bool) (string, string, error) { "upperStartCamelObject": camel, "withCache": withCache, "containsIndexCache": table.ContainsUniqueKey, - "lowerStartCamelPrimaryKey": stringx.From(table.PrimaryKey.Name.ToCamel()).UnTitle(), + "lowerStartCamelPrimaryKey": stringx.From(table.PrimaryKey.Name.ToCamel()).Untitle(), "dataType": table.PrimaryKey.DataType, "keys": strings.Join(keySet.KeysStr(), "\n"), "originalPrimaryKey": table.PrimaryKey.Name.Source(), @@ -52,7 +52,7 @@ func genDelete(table Table, withCache bool) (string, string, error) { deleteMethodOut, err := util.With("deleteMethod"). Parse(text). Execute(map[string]interface{}{ - "lowerStartCamelPrimaryKey": stringx.From(table.PrimaryKey.Name.ToCamel()).UnTitle(), + "lowerStartCamelPrimaryKey": stringx.From(table.PrimaryKey.Name.ToCamel()).Untitle(), "dataType": table.PrimaryKey.DataType, }) if err != nil { diff --git a/tools/goctl/model/sql/gen/findone.go b/tools/goctl/model/sql/gen/findone.go index b2af5f27..f7c157a2 100644 --- a/tools/goctl/model/sql/gen/findone.go +++ b/tools/goctl/model/sql/gen/findone.go @@ -18,9 +18,9 @@ func genFindOne(table Table, withCache bool) (string, string, error) { Execute(map[string]interface{}{ "withCache": withCache, "upperStartCamelObject": camel, - "lowerStartCamelObject": stringx.From(camel).UnTitle(), + "lowerStartCamelObject": stringx.From(camel).Untitle(), "originalPrimaryKey": table.PrimaryKey.Name.Source(), - "lowerStartCamelPrimaryKey": stringx.From(table.PrimaryKey.Name.ToCamel()).UnTitle(), + "lowerStartCamelPrimaryKey": stringx.From(table.PrimaryKey.Name.ToCamel()).Untitle(), "dataType": table.PrimaryKey.DataType, "cacheKey": table.CacheKey[table.PrimaryKey.Name.Source()].KeyExpression, "cacheKeyVariable": table.CacheKey[table.PrimaryKey.Name.Source()].Variable, @@ -38,7 +38,7 @@ func genFindOne(table Table, withCache bool) (string, string, error) { Parse(text). Execute(map[string]interface{}{ "upperStartCamelObject": camel, - "lowerStartCamelPrimaryKey": stringx.From(table.PrimaryKey.Name.ToCamel()).UnTitle(), + "lowerStartCamelPrimaryKey": stringx.From(table.PrimaryKey.Name.ToCamel()).Untitle(), "dataType": table.PrimaryKey.DataType, }) if err != nil { diff --git a/tools/goctl/model/sql/gen/findonebyfield.go b/tools/goctl/model/sql/gen/findonebyfield.go index aa8cdd97..6adea253 100644 --- a/tools/goctl/model/sql/gen/findonebyfield.go +++ b/tools/goctl/model/sql/gen/findonebyfield.go @@ -32,12 +32,12 @@ func genFindOneByField(table Table, withCache bool) (*findOneCode, error) { output, err := t.Execute(map[string]interface{}{ "upperStartCamelObject": camelTableName, "upperField": camelFieldName, - "in": fmt.Sprintf("%s %s", stringx.From(camelFieldName).UnTitle(), field.DataType), + "in": fmt.Sprintf("%s %s", stringx.From(camelFieldName).Untitle(), field.DataType), "withCache": withCache, "cacheKey": table.CacheKey[field.Name.Source()].KeyExpression, "cacheKeyVariable": table.CacheKey[field.Name.Source()].Variable, - "lowerStartCamelObject": stringx.From(camelTableName).UnTitle(), - "lowerStartCamelField": stringx.From(camelFieldName).UnTitle(), + "lowerStartCamelObject": stringx.From(camelTableName).Untitle(), + "lowerStartCamelField": stringx.From(camelFieldName).Untitle(), "upperStartCamelPrimaryKey": table.PrimaryKey.Name.ToCamel(), "originalField": field.Name.Source(), }) @@ -63,7 +63,7 @@ func genFindOneByField(table Table, withCache bool) (*findOneCode, error) { output, err := t.Execute(map[string]interface{}{ "upperStartCamelObject": camelTableName, "upperField": camelFieldName, - "in": fmt.Sprintf("%s %s", stringx.From(camelFieldName).UnTitle(), field.DataType), + "in": fmt.Sprintf("%s %s", stringx.From(camelFieldName).Untitle(), field.DataType), }) if err != nil { return nil, err @@ -81,7 +81,7 @@ func genFindOneByField(table Table, withCache bool) (*findOneCode, error) { out, err := util.With("findOneByFieldExtraMethod").Parse(text).Execute(map[string]interface{}{ "upperStartCamelObject": camelTableName, "primaryKeyLeft": table.CacheKey[table.PrimaryKey.Name.Source()].Left, - "lowerStartCamelObject": stringx.From(camelTableName).UnTitle(), + "lowerStartCamelObject": stringx.From(camelTableName).Untitle(), "originalPrimaryField": table.PrimaryKey.Name.Source(), }) if err != nil { diff --git a/tools/goctl/model/sql/gen/insert.go b/tools/goctl/model/sql/gen/insert.go index 9fcfc2eb..139e9c1b 100644 --- a/tools/goctl/model/sql/gen/insert.go +++ b/tools/goctl/model/sql/gen/insert.go @@ -45,7 +45,7 @@ func genInsert(table Table, withCache bool) (string, string, error) { "withCache": withCache, "containsIndexCache": table.ContainsUniqueKey, "upperStartCamelObject": camel, - "lowerStartCamelObject": stringx.From(camel).UnTitle(), + "lowerStartCamelObject": stringx.From(camel).Untitle(), "expression": strings.Join(expressions, ", "), "expressionValues": strings.Join(expressionValues, ", "), "keys": strings.Join(keySet.KeysStr(), "\n"), diff --git a/tools/goctl/model/sql/gen/keys.go b/tools/goctl/model/sql/gen/keys.go index f0f9b3c4..4d2ecd11 100644 --- a/tools/goctl/model/sql/gen/keys.go +++ b/tools/goctl/model/sql/gen/keys.go @@ -28,11 +28,11 @@ func genCacheKeys(table parser.Table) (map[string]Key, error) { fields := table.Fields m := make(map[string]Key) camelTableName := table.Name.ToCamel() - lowerStartCamelTableName := stringx.From(camelTableName).UnTitle() + lowerStartCamelTableName := stringx.From(camelTableName).Untitle() for _, field := range fields { if field.IsUniqueKey || field.IsPrimaryKey { camelFieldName := field.Name.ToCamel() - lowerStartCamelFieldName := stringx.From(camelFieldName).UnTitle() + lowerStartCamelFieldName := stringx.From(camelFieldName).Untitle() left := fmt.Sprintf("cache%s%sPrefix", camelTableName, camelFieldName) if strings.ToLower(camelFieldName) == strings.ToLower(camelTableName) { left = fmt.Sprintf("cache%sPrefix", camelTableName) diff --git a/tools/goctl/model/sql/gen/keys_test.go b/tools/goctl/model/sql/gen/keys_test.go index a2cf4882..261be176 100644 --- a/tools/goctl/model/sql/gen/keys_test.go +++ b/tools/goctl/model/sql/gen/keys_test.go @@ -62,11 +62,11 @@ func TestGenCacheKeys(t *testing.T) { for fieldName, key := range m { name := stringx.From(fieldName) - assert.Equal(t, fmt.Sprintf(`cacheUser%sPrefix = "cache#User#%s#"`, name.ToCamel(), name.UnTitle()), key.VarExpression) + assert.Equal(t, fmt.Sprintf(`cacheUser%sPrefix = "cache#User#%s#"`, name.ToCamel(), name.Untitle()), key.VarExpression) assert.Equal(t, fmt.Sprintf(`cacheUser%sPrefix`, name.ToCamel()), key.Left) - assert.Equal(t, fmt.Sprintf(`cache#User#%s#`, name.UnTitle()), key.Right) + assert.Equal(t, fmt.Sprintf(`cache#User#%s#`, name.Untitle()), key.Right) assert.Equal(t, fmt.Sprintf(`user%sKey`, name.ToCamel()), key.Variable) - assert.Equal(t, `user`+name.ToCamel()+`Key := fmt.Sprintf("%s%v", cacheUser`+name.ToCamel()+`Prefix,`+name.UnTitle()+`)`, key.KeyExpression) + assert.Equal(t, `user`+name.ToCamel()+`Key := fmt.Sprintf("%s%v", cacheUser`+name.ToCamel()+`Prefix,`+name.Untitle()+`)`, key.KeyExpression) } } diff --git a/tools/goctl/model/sql/gen/update.go b/tools/goctl/model/sql/gen/update.go index 677e02ec..6194b388 100644 --- a/tools/goctl/model/sql/gen/update.go +++ b/tools/goctl/model/sql/gen/update.go @@ -34,7 +34,7 @@ func genUpdate(table Table, withCache bool) (string, string, error) { "upperStartCamelObject": camelTableName, "primaryCacheKey": table.CacheKey[table.PrimaryKey.Name.Source()].DataKeyExpression, "primaryKeyVariable": table.CacheKey[table.PrimaryKey.Name.Source()].Variable, - "lowerStartCamelObject": stringx.From(camelTableName).UnTitle(), + "lowerStartCamelObject": stringx.From(camelTableName).Untitle(), "originalPrimaryKey": table.PrimaryKey.Name.Source(), "expressionValues": strings.Join(expressionValues, ", "), }) diff --git a/tools/goctl/model/sql/gen/vars.go b/tools/goctl/model/sql/gen/vars.go index 86ae57c1..78d49641 100644 --- a/tools/goctl/model/sql/gen/vars.go +++ b/tools/goctl/model/sql/gen/vars.go @@ -23,7 +23,7 @@ func genVars(table Table, withCache bool) (string, error) { Parse(text). GoFmt(true). Execute(map[string]interface{}{ - "lowerStartCamelObject": stringx.From(camel).UnTitle(), + "lowerStartCamelObject": stringx.From(camel).Untitle(), "upperStartCamelObject": camel, "cacheKeys": strings.Join(keys, "\n"), "autoIncrement": table.PrimaryKey.AutoIncrement, diff --git a/tools/goctl/rpc/generator/prototmpl.go b/tools/goctl/rpc/generator/prototmpl.go index a4afd242..e772a7f7 100644 --- a/tools/goctl/rpc/generator/prototmpl.go +++ b/tools/goctl/rpc/generator/prototmpl.go @@ -40,7 +40,7 @@ func ProtoTmpl(out string) error { } err = util.With("t").Parse(text).SaveTo(map[string]string{ - "package": serviceName.UnTitle(), + "package": serviceName.Untitle(), "serviceName": serviceName.Title(), }, out, false) return err diff --git a/tools/goctl/util/stringx/string.go b/tools/goctl/util/stringx/string.go index bc49de7e..e93fd9d1 100644 --- a/tools/goctl/util/stringx/string.go +++ b/tools/goctl/util/stringx/string.go @@ -6,11 +6,9 @@ import ( "unicode" ) -type ( - String struct { - source string - } -) +type String struct { + source string +} func From(data string) String { return String{source: data} @@ -30,8 +28,12 @@ func (s String) Lower() string { return strings.ToLower(s.source) } -func (s String) Upper() string { - return strings.ToUpper(s.source) +func (s String) ReplaceAll(old, new string) string { + return strings.ReplaceAll(s.source, old, new) +} + +func (s String) Source() string { + return s.source } func (s String) Title() string { @@ -64,7 +66,7 @@ func (s String) ToSnake() string { } // return original string if rune is not letter at index 0 -func (s String) UnTitle() string { +func (s String) Untitle() string { if s.IsEmptyOrSpace() { return s.source } @@ -75,6 +77,10 @@ func (s String) UnTitle() string { return string(unicode.ToLower(r)) + s.source[1:] } +func (s String) Upper() string { + return strings.ToUpper(s.source) +} + // it will not ignore spaces func (s String) splitBy(fn func(r rune) bool, remove bool) []string { if s.IsEmptyOrSpace() { @@ -100,11 +106,3 @@ func (s String) splitBy(fn func(r rune) bool, remove bool) []string { } return list } - -func (s String) ReplaceAll(old, new string) string { - return strings.ReplaceAll(s.source, old, new) -} - -func (s String) Source() string { - return s.source -}