fix(lint): Start to apply linter recommandation
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
5434cc15ce
commit
1d7730c078
12
cmd/init.go
12
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")
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -1,5 +1,5 @@
|
||||
package base
|
||||
|
||||
// ApiType
|
||||
type ApiType struct {
|
||||
// APIType
|
||||
type APIType struct {
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()))
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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())
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user