diff --git a/core/mapping/yamlunmarshaler.go b/core/mapping/yamlunmarshaler.go index 112638212b0d..01bf44695a59 100644 --- a/core/mapping/yamlunmarshaler.go +++ b/core/mapping/yamlunmarshaler.go @@ -3,8 +3,9 @@ package mapping import ( "encoding/json" "errors" - "gopkg.in/yaml.v2" "io" + + "gopkg.in/yaml.v2" ) // To make .json & .yaml consistent, we just use json as the tag key. @@ -27,45 +28,6 @@ func UnmarshalYamlReader(reader io.Reader, v interface{}) error { return unmarshalYamlReader(reader, v, yamlUnmarshaler) } -func unmarshalYamlBytes(content []byte, v interface{}, unmarshaler *Unmarshaler) error { - var o interface{} - if err := yamlUnmarshal(content, &o); err != nil { - return err - } - - if m, ok := o.(map[string]interface{}); ok { - return unmarshaler.Unmarshal(m, v) - } - - return ErrUnsupportedType -} - -func unmarshalYamlReader(reader io.Reader, v interface{}, unmarshaler *Unmarshaler) error { - var res interface{} - if err := yaml.NewDecoder(reader).Decode(&res); err != nil { - return err - } - - out := cleanupMapValue(res) - - if m, ok := out.(map[string]interface{}); ok { - return unmarshaler.Unmarshal(m, v) - } - - return ErrUnsupportedType -} - -// yamlUnmarshal YAML to map[string]interface{} instead of map[interface{}]interface{}. -func yamlUnmarshal(in []byte, out interface{}) error { - var res interface{} - if err := yaml.Unmarshal(in, &res); err != nil { - return err - } - - *out.(*interface{}) = cleanupMapValue(res) - return nil -} - func cleanupInterfaceMap(in map[interface{}]interface{}) map[string]interface{} { res := make(map[string]interface{}) for k, v := range in { @@ -100,3 +62,40 @@ func cleanupMapValue(v interface{}) interface{} { return Repr(v) } } + +func unmarshal(unmarshaler *Unmarshaler, o interface{}, v interface{}) error { + if m, ok := o.(map[string]interface{}); ok { + return unmarshaler.Unmarshal(m, v) + } + + return ErrUnsupportedType +} + +func unmarshalYamlBytes(content []byte, v interface{}, unmarshaler *Unmarshaler) error { + var o interface{} + if err := yamlUnmarshal(content, &o); err != nil { + return err + } + + return unmarshal(unmarshaler, o, v) +} + +func unmarshalYamlReader(reader io.Reader, v interface{}, unmarshaler *Unmarshaler) error { + var res interface{} + if err := yaml.NewDecoder(reader).Decode(&res); err != nil { + return err + } + + return unmarshal(unmarshaler, cleanupMapValue(res), v) +} + +// yamlUnmarshal YAML to map[string]interface{} instead of map[interface{}]interface{}. +func yamlUnmarshal(in []byte, out interface{}) error { + var res interface{} + if err := yaml.Unmarshal(in, &res); err != nil { + return err + } + + *out.(*interface{}) = cleanupMapValue(res) + return nil +} diff --git a/core/stores/redis/hook_test.go b/core/stores/redis/hook_test.go index 1d3dce5f1691..f1e993ab0015 100644 --- a/core/stores/redis/hook_test.go +++ b/core/stores/redis/hook_test.go @@ -8,7 +8,6 @@ import ( "time" red "github.com/go-redis/redis/v8" - "github.com/stretchr/testify/assert" ) diff --git a/tools/goctl/api/apigen/gen.go b/tools/goctl/api/apigen/gen.go index 7da3aa2f2177..32fc27d7dec1 100644 --- a/tools/goctl/api/apigen/gen.go +++ b/tools/goctl/api/apigen/gen.go @@ -8,9 +8,9 @@ import ( "text/template" "github.com/logrusorgru/aurora" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) const apiTemplate = ` diff --git a/tools/goctl/api/apigen/template.go b/tools/goctl/api/apigen/template.go index 265ff80aeef5..8237badd84df 100644 --- a/tools/goctl/api/apigen/template.go +++ b/tools/goctl/api/apigen/template.go @@ -3,8 +3,8 @@ package apigen import ( "fmt" - "github.com/zeromicro/go-zero/tools/goctl/util/pathx" "github.com/urfave/cli" + "github.com/zeromicro/go-zero/tools/goctl/util/pathx" ) const ( diff --git a/tools/goctl/api/dartgen/gen.go b/tools/goctl/api/dartgen/gen.go index 6edeb9daad63..3bb08a9911e4 100644 --- a/tools/goctl/api/dartgen/gen.go +++ b/tools/goctl/api/dartgen/gen.go @@ -4,9 +4,9 @@ import ( "errors" "strings" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/tools/goctl/api/parser" - "github.com/urfave/cli" ) // DartCommand create dart network request code diff --git a/tools/goctl/api/docgen/gen.go b/tools/goctl/api/docgen/gen.go index 62cd37fa0970..f298576ead2a 100644 --- a/tools/goctl/api/docgen/gen.go +++ b/tools/goctl/api/docgen/gen.go @@ -7,9 +7,9 @@ import ( "path/filepath" "strings" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/tools/goctl/api/parser" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) // DocCommand generate markdown doc file diff --git a/tools/goctl/api/format/format.go b/tools/goctl/api/format/format.go index 8f2fd9bca2ef..79672952f0d6 100644 --- a/tools/goctl/api/format/format.go +++ b/tools/goctl/api/format/format.go @@ -11,11 +11,11 @@ import ( "path/filepath" "strings" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/tools/goctl/api/parser" "github.com/zeromicro/go-zero/tools/goctl/api/util" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) const ( diff --git a/tools/goctl/api/gogen/gen.go b/tools/goctl/api/gogen/gen.go index 7e73f0b05dc2..2d3a0f6a2a96 100644 --- a/tools/goctl/api/gogen/gen.go +++ b/tools/goctl/api/gogen/gen.go @@ -12,6 +12,7 @@ import ( "time" "github.com/logrusorgru/aurora" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/core/logx" apiformat "github.com/zeromicro/go-zero/tools/goctl/api/format" "github.com/zeromicro/go-zero/tools/goctl/api/parser" @@ -19,7 +20,6 @@ import ( "github.com/zeromicro/go-zero/tools/goctl/config" "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) const tmpFile = "%s-%d" diff --git a/tools/goctl/api/gogen/template.go b/tools/goctl/api/gogen/template.go index 21addc6ff5f8..1089298f24cf 100644 --- a/tools/goctl/api/gogen/template.go +++ b/tools/goctl/api/gogen/template.go @@ -3,8 +3,8 @@ package gogen import ( "fmt" - "github.com/zeromicro/go-zero/tools/goctl/util/pathx" "github.com/urfave/cli" + "github.com/zeromicro/go-zero/tools/goctl/util/pathx" ) const ( diff --git a/tools/goctl/api/javagen/gen.go b/tools/goctl/api/javagen/gen.go index 8698012ba4a1..e21ffb37c47c 100644 --- a/tools/goctl/api/javagen/gen.go +++ b/tools/goctl/api/javagen/gen.go @@ -6,10 +6,10 @@ import ( "strings" "github.com/logrusorgru/aurora" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/tools/goctl/api/parser" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) // JavaCommand the generate java code command entrance diff --git a/tools/goctl/api/ktgen/cmd.go b/tools/goctl/api/ktgen/cmd.go index 04bd214b5163..f0168cf42a66 100644 --- a/tools/goctl/api/ktgen/cmd.go +++ b/tools/goctl/api/ktgen/cmd.go @@ -3,8 +3,8 @@ package ktgen import ( "errors" - "github.com/zeromicro/go-zero/tools/goctl/api/parser" "github.com/urfave/cli" + "github.com/zeromicro/go-zero/tools/goctl/api/parser" ) // KtCommand the generate kotlin code command entrance diff --git a/tools/goctl/api/new/newservice.go b/tools/goctl/api/new/newservice.go index 0b1618641023..f978aeec2842 100644 --- a/tools/goctl/api/new/newservice.go +++ b/tools/goctl/api/new/newservice.go @@ -7,11 +7,11 @@ import ( "strings" "text/template" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/tools/goctl/api/gogen" conf "github.com/zeromicro/go-zero/tools/goctl/config" "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) const apiTemplate = ` diff --git a/tools/goctl/api/new/template.go b/tools/goctl/api/new/template.go index 0e8f6dd15105..eab11cb0798d 100644 --- a/tools/goctl/api/new/template.go +++ b/tools/goctl/api/new/template.go @@ -3,8 +3,8 @@ package new import ( "fmt" - "github.com/zeromicro/go-zero/tools/goctl/util/pathx" "github.com/urfave/cli" + "github.com/zeromicro/go-zero/tools/goctl/util/pathx" ) const ( diff --git a/tools/goctl/api/parser/g4/ast/apiparser.go b/tools/goctl/api/parser/g4/ast/apiparser.go index b77474f0fbe9..29d69da34f96 100644 --- a/tools/goctl/api/parser/g4/ast/apiparser.go +++ b/tools/goctl/api/parser/g4/ast/apiparser.go @@ -7,9 +7,9 @@ import ( "path/filepath" "strings" + "github.com/zeromicro/antlr" "github.com/zeromicro/go-zero/tools/goctl/api/parser/g4/gen/api" "github.com/zeromicro/go-zero/tools/goctl/util/console" - "github.com/zeromicro/antlr" ) type ( diff --git a/tools/goctl/api/parser/g4/ast/ast.go b/tools/goctl/api/parser/g4/ast/ast.go index 22c825ac5bf3..6d31fbf00af1 100644 --- a/tools/goctl/api/parser/g4/ast/ast.go +++ b/tools/goctl/api/parser/g4/ast/ast.go @@ -5,9 +5,9 @@ import ( "sort" "strings" + "github.com/zeromicro/antlr" "github.com/zeromicro/go-zero/tools/goctl/api/parser/g4/gen/api" "github.com/zeromicro/go-zero/tools/goctl/util/console" - "github.com/zeromicro/antlr" ) type ( diff --git a/tools/goctl/api/tsgen/gen.go b/tools/goctl/api/tsgen/gen.go index 6e007648b76c..063f5f596536 100644 --- a/tools/goctl/api/tsgen/gen.go +++ b/tools/goctl/api/tsgen/gen.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/logrusorgru/aurora" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/tools/goctl/api/parser" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) // TsCommand provides the entry to generate typescript codes diff --git a/tools/goctl/api/validate/validate.go b/tools/goctl/api/validate/validate.go index 97b8d56e78f2..ca4302538077 100644 --- a/tools/goctl/api/validate/validate.go +++ b/tools/goctl/api/validate/validate.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/logrusorgru/aurora" - "github.com/zeromicro/go-zero/tools/goctl/api/parser" "github.com/urfave/cli" + "github.com/zeromicro/go-zero/tools/goctl/api/parser" ) // GoValidateApi verifies whether the api has a syntax error diff --git a/tools/goctl/bug/bug.go b/tools/goctl/bug/bug.go index 33a6a87463fa..a497e29485f6 100644 --- a/tools/goctl/bug/bug.go +++ b/tools/goctl/bug/bug.go @@ -6,8 +6,8 @@ import ( "os/exec" "runtime" - "github.com/zeromicro/go-zero/tools/goctl/internal/version" "github.com/urfave/cli" + "github.com/zeromicro/go-zero/tools/goctl/internal/version" ) const ( diff --git a/tools/goctl/docker/docker.go b/tools/goctl/docker/docker.go index 9b9c772dc04e..e17165a7111c 100644 --- a/tools/goctl/docker/docker.go +++ b/tools/goctl/docker/docker.go @@ -10,9 +10,9 @@ import ( "time" "github.com/logrusorgru/aurora" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) const ( diff --git a/tools/goctl/docker/template.go b/tools/goctl/docker/template.go index ba0e94d462f3..929b8026fe60 100644 --- a/tools/goctl/docker/template.go +++ b/tools/goctl/docker/template.go @@ -1,8 +1,8 @@ package docker import ( - "github.com/zeromicro/go-zero/tools/goctl/util/pathx" "github.com/urfave/cli" + "github.com/zeromicro/go-zero/tools/goctl/util/pathx" ) const ( diff --git a/tools/goctl/kube/kube.go b/tools/goctl/kube/kube.go index 97bc7f4fd7eb..8befbb0ad71f 100644 --- a/tools/goctl/kube/kube.go +++ b/tools/goctl/kube/kube.go @@ -6,9 +6,9 @@ import ( "text/template" "github.com/logrusorgru/aurora" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) const ( diff --git a/tools/goctl/model/mongo/generate/template.go b/tools/goctl/model/mongo/generate/template.go index 89c525eff54b..644250e837ce 100644 --- a/tools/goctl/model/mongo/generate/template.go +++ b/tools/goctl/model/mongo/generate/template.go @@ -3,9 +3,9 @@ package generate import ( "fmt" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/tools/goctl/model/mongo/template" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) const ( diff --git a/tools/goctl/model/mongo/mongo.go b/tools/goctl/model/mongo/mongo.go index 3a408e575bd9..6d8074766e27 100644 --- a/tools/goctl/model/mongo/mongo.go +++ b/tools/goctl/model/mongo/mongo.go @@ -5,11 +5,11 @@ import ( "path/filepath" "strings" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/tools/goctl/config" "github.com/zeromicro/go-zero/tools/goctl/model/mongo/generate" file "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) // Action provides the entry for goctl mongo code generation. diff --git a/tools/goctl/model/sql/command/command.go b/tools/goctl/model/sql/command/command.go index 59753ee68bc5..f313072ec452 100644 --- a/tools/goctl/model/sql/command/command.go +++ b/tools/goctl/model/sql/command/command.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/go-sql-driver/mysql" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/stores/postgres" "github.com/zeromicro/go-zero/core/stores/sqlx" @@ -16,7 +17,6 @@ import ( file "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/console" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) const ( diff --git a/tools/goctl/model/sql/gen/template.go b/tools/goctl/model/sql/gen/template.go index 6287e42197f9..d9a664d4102d 100644 --- a/tools/goctl/model/sql/gen/template.go +++ b/tools/goctl/model/sql/gen/template.go @@ -3,9 +3,9 @@ package gen import ( "fmt" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/tools/goctl/model/sql/template" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) const ( diff --git a/tools/goctl/model/sql/parser/parser.go b/tools/goctl/model/sql/parser/parser.go index 11c4c9a417be..ab992083ac09 100644 --- a/tools/goctl/model/sql/parser/parser.go +++ b/tools/goctl/model/sql/parser/parser.go @@ -6,6 +6,7 @@ import ( "sort" "strings" + "github.com/zeromicro/ddl-parser/parser" "github.com/zeromicro/go-zero/core/collection" "github.com/zeromicro/go-zero/tools/goctl/model/sql/converter" "github.com/zeromicro/go-zero/tools/goctl/model/sql/model" @@ -13,7 +14,6 @@ import ( su "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/console" "github.com/zeromicro/go-zero/tools/goctl/util/stringx" - "github.com/zeromicro/ddl-parser/parser" ) const timeImport = "time.Time" diff --git a/tools/goctl/plugin/plugin.go b/tools/goctl/plugin/plugin.go index c9cb97f0e683..50ea181e874d 100644 --- a/tools/goctl/plugin/plugin.go +++ b/tools/goctl/plugin/plugin.go @@ -13,11 +13,11 @@ import ( "path/filepath" "strings" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/tools/goctl/api/parser" "github.com/zeromicro/go-zero/tools/goctl/api/spec" "github.com/zeromicro/go-zero/tools/goctl/rpc/execx" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) const pluginArg = "_plugin" diff --git a/tools/goctl/rpc/cli/cli.go b/tools/goctl/rpc/cli/cli.go index e02f6345f4be..a139056df7de 100644 --- a/tools/goctl/rpc/cli/cli.go +++ b/tools/goctl/rpc/cli/cli.go @@ -6,12 +6,12 @@ import ( "path/filepath" "runtime" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/tools/goctl/rpc/generator" "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/console" "github.com/zeromicro/go-zero/tools/goctl/util/env" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) // Deprecated: use ZRPC instead. diff --git a/tools/goctl/rpc/generator/template.go b/tools/goctl/rpc/generator/template.go index 864977861b8a..c703406b6306 100644 --- a/tools/goctl/rpc/generator/template.go +++ b/tools/goctl/rpc/generator/template.go @@ -3,8 +3,8 @@ package generator import ( "fmt" - "github.com/zeromicro/go-zero/tools/goctl/util/pathx" "github.com/urfave/cli" + "github.com/zeromicro/go-zero/tools/goctl/util/pathx" ) const ( diff --git a/tools/goctl/tpl/templates.go b/tools/goctl/tpl/templates.go index 3ffde0c523a3..e6127180a0f8 100644 --- a/tools/goctl/tpl/templates.go +++ b/tools/goctl/tpl/templates.go @@ -5,6 +5,7 @@ import ( "path/filepath" "github.com/logrusorgru/aurora" + "github.com/urfave/cli" "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/tools/goctl/api/apigen" "github.com/zeromicro/go-zero/tools/goctl/api/gogen" @@ -15,7 +16,6 @@ import ( modelgen "github.com/zeromicro/go-zero/tools/goctl/model/sql/gen" rpcgen "github.com/zeromicro/go-zero/tools/goctl/rpc/generator" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/urfave/cli" ) const templateParentPath = "/" diff --git a/tools/goctl/upgrade/upgrade.go b/tools/goctl/upgrade/upgrade.go index e2c91ce13eb4..d8dac0d8e9d9 100644 --- a/tools/goctl/upgrade/upgrade.go +++ b/tools/goctl/upgrade/upgrade.go @@ -4,8 +4,8 @@ import ( "fmt" "runtime" - "github.com/zeromicro/go-zero/tools/goctl/rpc/execx" "github.com/urfave/cli" + "github.com/zeromicro/go-zero/tools/goctl/rpc/execx" ) // Upgrade gets the latest goctl by