From a3c953c7a49ed8c206a3cbf63e2a351d8d629f65 Mon Sep 17 00:00:00 2001 From: Matthieu 'JP' DERASSE Date: Mon, 25 Jul 2022 20:57:00 +0000 Subject: [PATCH] fix(clean): Fix import order, func name, ... --- cmd/init.go | 10 ++++++++-- helpers/api_type/api_type.go | 12 +++++++++++- helpers/api_type/enum.go | 9 +++++---- helpers/api_type/gin_gonic/api_type.go | 5 ++++- helpers/input.go | 7 ++++--- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index 9570cf3..c998235 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -92,9 +92,15 @@ func runInitAction(cmd *cobra.Command, args []string) { } log.Infof("Which kind of API do you want to init (possible values: %s)", strings.Join(possibleApiTypes, ", ")) - apiType := helpers.ApiTypeInput() + apiTypeName := helpers.ApiTypeNameInput() + + log.Debugf("Using api type : %s", string(apiTypeName)) + + _, err = api_type.GetApiType(apiTypeName) + if err != nil { + log.Error("Impossible to load that API Type generator") + } - log.Debugf("Using api type : %s", apiType) // XXX: // Check we are in gopath or ask for the gomod name // Create directory diff --git a/helpers/api_type/api_type.go b/helpers/api_type/api_type.go index 82c2eb6..4160f02 100644 --- a/helpers/api_type/api_type.go +++ b/helpers/api_type/api_type.go @@ -1,6 +1,12 @@ package api_type -import "github.com/juju/errors" +import ( + "github.com/juju/errors" + + "git.home.m-and-m.ovh/mderasse/boot/helpers/api_type/gin_gonic" + "git.home.m-and-m.ovh/mderasse/boot/helpers/api_type/go_swagger" + "git.home.m-and-m.ovh/mderasse/boot/helpers/api_type/mojolicious" +) func GetApiType(in ApiTypeName) (ApiTypeInterface, error) { if in == "" { @@ -13,8 +19,12 @@ func GetApiType(in ApiTypeName) (ApiTypeInterface, error) { switch in { case ApyTypeName_GIN_GONIC: + return gin_gonic.ApiType{}, nil case ApyTypeName_GO_SWAGGER: + return go_swagger.ApiType{}, nil case ApyTypeName_MOJOLICIOUS: + return mojolicious.ApiType{}, nil } + return nil, errors.NotFoundf("Unknown Api Type") } diff --git a/helpers/api_type/enum.go b/helpers/api_type/enum.go index 58d37d3..c8e85e0 100644 --- a/helpers/api_type/enum.go +++ b/helpers/api_type/enum.go @@ -10,17 +10,17 @@ import ( type ApiTypeName string const ( - ApyTypeName_NULL ApiTypeName = "" - ApyTypeName_GO_SWAGGER ApiTypeName = "Go Swagger" ApyTypeName_GIN_GONIC ApiTypeName = "Gin Gonic" + ApyTypeName_GO_SWAGGER ApiTypeName = "Go Swagger" ApyTypeName_MOJOLICIOUS ApiTypeName = "Mojolicious" + ApyTypeName_NULL ApiTypeName = "" ) // GetListOfApiTypeName returns a list of ApiTypeName func GetListOfApiTypeName() []ApiTypeName { return []ApiTypeName{ - ApyTypeName_GO_SWAGGER, ApyTypeName_GIN_GONIC, + ApyTypeName_GO_SWAGGER, ApyTypeName_MOJOLICIOUS, } } @@ -47,7 +47,8 @@ func NewApiTypeName(in string) (ApiTypeName, error) { return out, nil } -func NewApiTypeFromInput(in string) (ApiTypeName, error) { +// NewApiTypeNameFromInput +func NewApiTypeNameFromInput(in string) (ApiTypeName, error) { in = strings.ToLower(in) in = strings.ReplaceAll(in, " ", "-") diff --git a/helpers/api_type/gin_gonic/api_type.go b/helpers/api_type/gin_gonic/api_type.go index 50bc24f..d77690f 100644 --- a/helpers/api_type/gin_gonic/api_type.go +++ b/helpers/api_type/gin_gonic/api_type.go @@ -1,5 +1,8 @@ -package base +package gin_gonic + +import "git.home.m-and-m.ovh/mderasse/boot/helpers/api_type/base" // ApiType type ApiType struct { + base.ApiType } diff --git a/helpers/input.go b/helpers/input.go index 427dfaa..8690d5c 100644 --- a/helpers/input.go +++ b/helpers/input.go @@ -6,6 +6,7 @@ import ( "strings" "git.home.m-and-m.ovh/mderasse/boot/helpers/api_type" + log "github.com/sirupsen/logrus" ) @@ -54,8 +55,8 @@ func PathInput() string { } } -// ApiTypeInput -func ApiTypeInput() api_type.ApiTypeName { +// ApiTypeNameInput +func ApiTypeNameInput() api_type.ApiTypeName { var possibleApiTypes []string for _, apiType := range api_type.GetListOfApiTypeName() { @@ -68,7 +69,7 @@ func ApiTypeInput() api_type.ApiTypeName { scanner.Scan() userInput := scanner.Text() - apiTypeName, err := api_type.NewApiTypeFromInput(userInput) + apiTypeName, err := api_type.NewApiTypeNameFromInput(userInput) if err != nil { log.Warnf("invalid API type (possible values: %s)", strings.Join(possibleApiTypes, ", ")) continue