From 1d7730c0787ffd19c146475260207df7d7e6687b Mon Sep 17 00:00:00 2001 From: Matthieu 'JP' DERASSE Date: Tue, 2 Aug 2022 20:33:47 +0000 Subject: [PATCH] fix(lint): Start to apply linter recommandation --- cmd/init.go | 12 ++--- helpers/api_types/api_type.go | 14 +++--- helpers/api_types/base/api_type.go | 4 +- helpers/api_types/base/check_initialize.go | 2 +- helpers/api_types/base/get_name.go | 4 +- helpers/api_types/base/get_user_input.go | 2 +- helpers/api_types/gin_gonic/api_type.go | 6 +-- helpers/api_types/gin_gonic/get_name.go | 4 +- helpers/api_types/go_swagger/api_type.go | 6 +-- .../api_types/go_swagger/check_initialize.go | 2 +- helpers/api_types/go_swagger/get_name.go | 4 +- .../api_types/go_swagger/get_user_input.go | 2 +- helpers/api_types/interface.go | 6 +-- helpers/api_types/mojolicious/api_type.go | 6 +-- helpers/api_types/mojolicious/get_name.go | 4 +- helpers/dependencies/golang.go | 16 +++---- helpers/dependencies/swagger.go | 10 ++-- helpers/input.go | 14 +++--- helpers/models/api_type_name_enum.go | 46 +++++++++---------- 19 files changed, 82 insertions(+), 82 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index 8915208..2b34578 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -90,17 +90,17 @@ func runInitAction(cmd *cobra.Command, args []string) { } // ask which API type we want to use - var possibleApiTypes []string - for _, apiType := range models.GetListOfApiTypeName() { - possibleApiTypes = append(possibleApiTypes, string(apiType)) + var possibleAPITypes []string + for _, apiType := range models.GetListOfAPITypeName() { + possibleAPITypes = append(possibleAPITypes, string(apiType)) } - log.Infof("Which kind of API do you want to init (possible values: %s)", strings.Join(possibleApiTypes, ", ")) - apiTypeName := helpers.ApiTypeNameInput() + log.Infof("Which kind of API do you want to init (possible values: %s)", strings.Join(possibleAPITypes, ", ")) + apiTypeName := helpers.APITypeNameInput() log.Debugf("Using api type : %s", string(apiTypeName)) - apiType, err := api_types.GetApiType(apiTypeName) + apiType, err := api_types.GetAPIType(apiTypeName) if err != nil { log.Error("Impossible to load that API Type generator") } diff --git a/helpers/api_types/api_type.go b/helpers/api_types/api_type.go index 8cf29f6..0b0545f 100644 --- a/helpers/api_types/api_type.go +++ b/helpers/api_types/api_type.go @@ -9,7 +9,7 @@ import ( "git.home.m-and-m.ovh/mderasse/gouick/helpers/models" ) -func GetApiType(in models.ApiTypeName) (ApiTypeInterface, error) { +func GetAPIType(in models.APITypeName) (APITypeInterface, error) { if in == "" { return nil, errors.BadRequestf("missing parameter") } @@ -19,12 +19,12 @@ func GetApiType(in models.ApiTypeName) (ApiTypeInterface, error) { } switch in { - case models.ApiTypeName_GIN_GONIC: - return gin_gonic.ApiType{}, nil - case models.ApiTypeName_GO_SWAGGER: - return go_swagger.ApiType{}, nil - case models.ApiTypeName_MOJOLICIOUS: - return mojolicious.ApiType{}, nil + case models.APITypeName_GIN_GONIC: + return gin_gonic.APIType{}, nil + case models.APITypeName_GO_SWAGGER: + return go_swagger.APIType{}, nil + case models.APITypeName_MOJOLICIOUS: + return mojolicious.APIType{}, nil } return nil, errors.NotFoundf("Unknown Api Type") diff --git a/helpers/api_types/base/api_type.go b/helpers/api_types/base/api_type.go index 50bc24f..0303fea 100644 --- a/helpers/api_types/base/api_type.go +++ b/helpers/api_types/base/api_type.go @@ -1,5 +1,5 @@ package base -// ApiType -type ApiType struct { +// APIType +type APIType struct { } diff --git a/helpers/api_types/base/check_initialize.go b/helpers/api_types/base/check_initialize.go index 2a5a329..4289696 100644 --- a/helpers/api_types/base/check_initialize.go +++ b/helpers/api_types/base/check_initialize.go @@ -5,7 +5,7 @@ import ( ) // CheckInitialize -func (a ApiType) CheckInitialize() error { +func (a APIType) CheckInitialize() error { return errors.NotImplementedf("CheckInitialize not implemented for %s", a.GetName()) } diff --git a/helpers/api_types/base/get_name.go b/helpers/api_types/base/get_name.go index be2948e..846d711 100644 --- a/helpers/api_types/base/get_name.go +++ b/helpers/api_types/base/get_name.go @@ -4,6 +4,6 @@ import ( "git.home.m-and-m.ovh/mderasse/gouick/helpers/models" ) -func (a ApiType) GetName() models.ApiTypeName { - return models.ApiTypeName_NULL +func (a APIType) GetName() models.APITypeName { + return models.APITypeName_NULL } diff --git a/helpers/api_types/base/get_user_input.go b/helpers/api_types/base/get_user_input.go index 66ffe35..7049968 100644 --- a/helpers/api_types/base/get_user_input.go +++ b/helpers/api_types/base/get_user_input.go @@ -6,7 +6,7 @@ import ( "github.com/juju/errors" ) -func (a ApiType) GetInitializeUserInput(params *models.UserInputParams) (*models.UserInputParams, error) { +func (a APIType) GetInitializeUserInput(params *models.UserInputParams) (*models.UserInputParams, error) { return nil, errors.NotImplementedf("GetInitializeUserInput not implemented for %s", a.GetName()) } diff --git a/helpers/api_types/gin_gonic/api_type.go b/helpers/api_types/gin_gonic/api_type.go index 691774a..664ba1c 100644 --- a/helpers/api_types/gin_gonic/api_type.go +++ b/helpers/api_types/gin_gonic/api_type.go @@ -2,7 +2,7 @@ package gin_gonic import "git.home.m-and-m.ovh/mderasse/gouick/helpers/api_types/base" -// ApiType -type ApiType struct { - base.ApiType +// APIType +type APIType struct { + base.APIType } diff --git a/helpers/api_types/gin_gonic/get_name.go b/helpers/api_types/gin_gonic/get_name.go index 79da30e..b0ab2f7 100644 --- a/helpers/api_types/gin_gonic/get_name.go +++ b/helpers/api_types/gin_gonic/get_name.go @@ -4,6 +4,6 @@ import ( "git.home.m-and-m.ovh/mderasse/gouick/helpers/models" ) -func (a ApiType) GetName() models.ApiTypeName { - return models.ApiTypeName_GIN_GONIC +func (a APIType) GetName() models.APITypeName { + return models.APITypeName_GIN_GONIC } diff --git a/helpers/api_types/go_swagger/api_type.go b/helpers/api_types/go_swagger/api_type.go index 41fd5e1..955fed1 100644 --- a/helpers/api_types/go_swagger/api_type.go +++ b/helpers/api_types/go_swagger/api_type.go @@ -2,7 +2,7 @@ package go_swagger import "git.home.m-and-m.ovh/mderasse/gouick/helpers/api_types/base" -// ApiType -type ApiType struct { - base.ApiType +// APIType +type APIType struct { + base.APIType } diff --git a/helpers/api_types/go_swagger/check_initialize.go b/helpers/api_types/go_swagger/check_initialize.go index c76585c..5977501 100644 --- a/helpers/api_types/go_swagger/check_initialize.go +++ b/helpers/api_types/go_swagger/check_initialize.go @@ -11,7 +11,7 @@ import ( ) // CheckInitialize -func (a ApiType) CheckInitialize() error { +func (a APIType) CheckInitialize() error { log.Debugf("Starting %s check initialize", string(a.GetName())) diff --git a/helpers/api_types/go_swagger/get_name.go b/helpers/api_types/go_swagger/get_name.go index f9e5ac0..05ee310 100644 --- a/helpers/api_types/go_swagger/get_name.go +++ b/helpers/api_types/go_swagger/get_name.go @@ -4,6 +4,6 @@ import ( "git.home.m-and-m.ovh/mderasse/gouick/helpers/models" ) -func (a ApiType) GetName() models.ApiTypeName { - return models.ApiTypeName_GO_SWAGGER +func (a APIType) GetName() models.APITypeName { + return models.APITypeName_GO_SWAGGER } diff --git a/helpers/api_types/go_swagger/get_user_input.go b/helpers/api_types/go_swagger/get_user_input.go index aa8d2d4..f744927 100644 --- a/helpers/api_types/go_swagger/get_user_input.go +++ b/helpers/api_types/go_swagger/get_user_input.go @@ -12,7 +12,7 @@ import ( ) // GetInitializeUserInput -func (a ApiType) GetInitializeUserInput(params *models.UserInputParams) (*models.UserInputParams, error) { +func (a APIType) GetInitializeUserInput(params *models.UserInputParams) (*models.UserInputParams, error) { log.Debugf("Starting %s user input", a.GetName()) diff --git a/helpers/api_types/interface.go b/helpers/api_types/interface.go index 6655b51..d8ece1d 100644 --- a/helpers/api_types/interface.go +++ b/helpers/api_types/interface.go @@ -2,9 +2,9 @@ package api_types import "git.home.m-and-m.ovh/mderasse/gouick/helpers/models" -// ApiTypeInterface -type ApiTypeInterface interface { +// APITypeInterface +type APITypeInterface interface { CheckInitialize() error - GetName() models.ApiTypeName + GetName() models.APITypeName GetInitializeUserInput(params *models.UserInputParams) (*models.UserInputParams, error) } diff --git a/helpers/api_types/mojolicious/api_type.go b/helpers/api_types/mojolicious/api_type.go index ab8b63d..39ed643 100644 --- a/helpers/api_types/mojolicious/api_type.go +++ b/helpers/api_types/mojolicious/api_type.go @@ -2,7 +2,7 @@ package mojolicious import "git.home.m-and-m.ovh/mderasse/gouick/helpers/api_types/base" -// ApiType -type ApiType struct { - base.ApiType +// APIType +type APIType struct { + base.APIType } diff --git a/helpers/api_types/mojolicious/get_name.go b/helpers/api_types/mojolicious/get_name.go index f534c4f..ed2c3a2 100644 --- a/helpers/api_types/mojolicious/get_name.go +++ b/helpers/api_types/mojolicious/get_name.go @@ -4,6 +4,6 @@ import ( "git.home.m-and-m.ovh/mderasse/gouick/helpers/models" ) -func (a ApiType) GetName() models.ApiTypeName { - return models.ApiTypeName_MOJOLICIOUS +func (a APIType) GetName() models.APITypeName { + return models.APITypeName_MOJOLICIOUS } diff --git a/helpers/dependencies/golang.go b/helpers/dependencies/golang.go index 07953f3..56bdd08 100644 --- a/helpers/dependencies/golang.go +++ b/helpers/dependencies/golang.go @@ -147,7 +147,7 @@ func (g Golang) DescribeInstall(path string) string { commands := []string{ "The following commands will be executed", fmt.Sprintf("rm -rf %s/* ", path), - fmt.Sprintf("curl %s | tar --strip-components=1 -C %s -zxf -", g.getDownloadUrl(), path), + fmt.Sprintf("curl %s | tar --strip-components=1 -C %s -zxf -", g.getDownloadURL(), path), } return strings.Join(commands, "\n") @@ -161,10 +161,10 @@ func (g Golang) Install(path string) error { log.Warnf("fail to delete content of directory %s", path) } - downloadUrl := g.getDownloadUrl() - content, err := downloadFile(downloadUrl) + downloadURL := g.getDownloadURL() + content, err := downloadFile(downloadURL) if err != nil { - log.Warnf("fail to download file from %s", downloadUrl) + log.Warnf("fail to download file from %s", downloadURL) return errors.Trace(err) } @@ -175,7 +175,7 @@ func (g Golang) Install(path string) error { err = unZip(content, "go/", path) if err != nil { - log.Warnf("fail to un-zip downloaded file from %s", downloadUrl) + log.Warnf("fail to un-zip downloaded file from %s", downloadURL) return errors.Trace(err) } @@ -185,13 +185,13 @@ func (g Golang) Install(path string) error { gzipReader, err := unGzip(content) if err != nil { - log.Warnf("fail to un-gzip downloaded file from %s, error:", downloadUrl) + log.Warnf("fail to un-gzip downloaded file from %s, error:", downloadURL) return errors.Trace(err) } err = unTar(gzipReader, "go/", path) if err != nil { - log.Warnf("fail to un-tar downloaded file from %s", downloadUrl) + log.Warnf("fail to un-tar downloaded file from %s", downloadURL) return errors.Trace(err) } } @@ -335,7 +335,7 @@ func (g Golang) GetInstallDirectory() (string, error) { return cleanOut, nil } -func (g Golang) getDownloadUrl() string { +func (g Golang) getDownloadURL() string { if runtime.GOOS == "windows" { return fmt.Sprintf("https://dl.google.com/go/go%s.%s-%s.zip", minimumGolangVersion, runtime.GOOS, runtime.GOARCH) diff --git a/helpers/dependencies/swagger.go b/helpers/dependencies/swagger.go index 40f5df7..2b363c8 100644 --- a/helpers/dependencies/swagger.go +++ b/helpers/dependencies/swagger.go @@ -146,7 +146,7 @@ func (s Swagger) DescribeInstall(path string) string { commands := []string{ "The following commands will be executed", fmt.Sprintf("rm -rf %s/swagger ", path), - fmt.Sprintf("wget %s -O %s/swagger", s.getDownloadUrl(), path), + fmt.Sprintf("wget %s -O %s/swagger", s.getDownloadURL(), path), fmt.Sprintf("chmod 644 %s/swagger", path), } @@ -156,10 +156,10 @@ func (s Swagger) DescribeInstall(path string) string { // Install func (s Swagger) Install(path string) error { - downloadUrl := s.getDownloadUrl() - content, err := downloadFile(downloadUrl) + downloadURL := s.getDownloadURL() + content, err := downloadFile(downloadURL) if err != nil { - log.Warnf("fail to download file from %s", downloadUrl) + log.Warnf("fail to download file from %s", downloadURL) return errors.Trace(err) } @@ -276,7 +276,7 @@ func (s Swagger) GetInstallDirectory() (string, error) { return strings.TrimSuffix(binaryPath, "/swagger"), nil } -func (s Swagger) getDownloadUrl() string { +func (s Swagger) getDownloadURL() string { return fmt.Sprintf("https://github.com/go-swagger/go-swagger/releases/download/v%s/swagger_%s_%s", minimumSwaggerVersion, runtime.GOOS, runtime.GOARCH) } diff --git a/helpers/input.go b/helpers/input.go index 3922fea..8cdb624 100644 --- a/helpers/input.go +++ b/helpers/input.go @@ -103,12 +103,12 @@ func PathInput() string { } } -// ApiTypeNameInput -func ApiTypeNameInput() models.ApiTypeName { +// APITypeNameInput +func APITypeNameInput() models.APITypeName { - var possibleApiTypes []string - for _, apiType := range models.GetListOfApiTypeName() { - possibleApiTypes = append(possibleApiTypes, string(apiType)) + var possibleAPITypes []string + for _, apiType := range models.GetListOfAPITypeName() { + possibleAPITypes = append(possibleAPITypes, string(apiType)) } scanner := bufio.NewScanner(os.Stdin) @@ -122,9 +122,9 @@ func ApiTypeNameInput() models.ApiTypeName { continue } - apiTypeName, err := models.NewApiTypeNameFromInput(userInput) + apiTypeName, err := models.NewAPITypeNameFromInput(userInput) if err != nil { - log.Warnf("invalid API type (possible values: %s)", strings.Join(possibleApiTypes, ", ")) + log.Warnf("invalid API type (possible values: %s)", strings.Join(possibleAPITypes, ", ")) continue } diff --git a/helpers/models/api_type_name_enum.go b/helpers/models/api_type_name_enum.go index eed390f..4ba5a1a 100644 --- a/helpers/models/api_type_name_enum.go +++ b/helpers/models/api_type_name_enum.go @@ -6,28 +6,28 @@ import ( "github.com/juju/errors" ) -// ApiTypeName -type ApiTypeName string +// APITypeName +type APITypeName string const ( - ApiTypeName_GIN_GONIC ApiTypeName = "Gin Gonic" - ApiTypeName_GO_SWAGGER ApiTypeName = "Go Swagger" - ApiTypeName_MOJOLICIOUS ApiTypeName = "Mojolicious" - ApiTypeName_NULL ApiTypeName = "" + APITypeName_GIN_GONIC APITypeName = "Gin Gonic" + APITypeName_GO_SWAGGER APITypeName = "Go Swagger" + APITypeName_MOJOLICIOUS APITypeName = "Mojolicious" + APITypeName_NULL APITypeName = "" ) -// GetListOfApiTypeName returns a list of ApiTypeName -func GetListOfApiTypeName() []ApiTypeName { - return []ApiTypeName{ - ApiTypeName_GIN_GONIC, - ApiTypeName_GO_SWAGGER, - ApiTypeName_MOJOLICIOUS, +// GetListOfAPITypeName returns a list of APITypeName +func GetListOfAPITypeName() []APITypeName { + return []APITypeName{ + APITypeName_GIN_GONIC, + APITypeName_GO_SWAGGER, + APITypeName_MOJOLICIOUS, } } // IsValid validates enum values -func (e ApiTypeName) IsValid() bool { - for _, v := range GetListOfApiTypeName() { +func (e APITypeName) IsValid() bool { + for _, v := range GetListOfAPITypeName() { if e == v { return true } @@ -36,27 +36,27 @@ func (e ApiTypeName) IsValid() bool { return false } -func NewApiTypeName(in string) (ApiTypeName, error) { - out := ApiTypeName_NULL +func NewAPITypeName(in string) (APITypeName, error) { + out := APITypeName_NULL if in != "" { - out = ApiTypeName(in) + out = APITypeName(in) if !out.IsValid() { - return ApiTypeName_NULL, errors.BadRequestf("Value %s invalid for enum ApiTypeName", in) + return APITypeName_NULL, errors.BadRequestf("Value %s invalid for enum APITypeName", in) } } return out, nil } -// NewApiTypeNameFromInput -func NewApiTypeNameFromInput(in string) (ApiTypeName, error) { +// NewAPITypeNameFromInput +func NewAPITypeNameFromInput(in string) (APITypeName, error) { in = strings.ToLower(in) in = strings.ReplaceAll(in, " ", "-") in = strings.ReplaceAll(in, "_", "-") - out := ApiTypeName_NULL + out := APITypeName_NULL if in != "" { - for _, apiTypeName := range GetListOfApiTypeName() { + for _, apiTypeName := range GetListOfAPITypeName() { apiTypeStr := strings.ToLower(string(apiTypeName)) apiTypeStr = strings.ReplaceAll(apiTypeStr, " ", "-") apiTypeStr = strings.ReplaceAll(apiTypeStr, "_", "-") @@ -64,7 +64,7 @@ func NewApiTypeNameFromInput(in string) (ApiTypeName, error) { return apiTypeName, nil } } - return ApiTypeName_NULL, errors.BadRequestf("Value %s invalid for enum ApiTypeName", in) + return APITypeName_NULL, errors.BadRequestf("Value %s invalid for enum APITypeName", in) } return out, nil }