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
|
// ask which API type we want to use
|
||||||
var possibleApiTypes []string
|
var possibleAPITypes []string
|
||||||
for _, apiType := range models.GetListOfApiTypeName() {
|
for _, apiType := range models.GetListOfAPITypeName() {
|
||||||
possibleApiTypes = append(possibleApiTypes, string(apiType))
|
possibleAPITypes = append(possibleAPITypes, string(apiType))
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Which kind of API do you want to init (possible values: %s)", strings.Join(possibleApiTypes, ", "))
|
log.Infof("Which kind of API do you want to init (possible values: %s)", strings.Join(possibleAPITypes, ", "))
|
||||||
apiTypeName := helpers.ApiTypeNameInput()
|
apiTypeName := helpers.APITypeNameInput()
|
||||||
|
|
||||||
log.Debugf("Using api type : %s", string(apiTypeName))
|
log.Debugf("Using api type : %s", string(apiTypeName))
|
||||||
|
|
||||||
apiType, err := api_types.GetApiType(apiTypeName)
|
apiType, err := api_types.GetAPIType(apiTypeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Impossible to load that API Type generator")
|
log.Error("Impossible to load that API Type generator")
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"git.home.m-and-m.ovh/mderasse/gouick/helpers/models"
|
"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 == "" {
|
if in == "" {
|
||||||
return nil, errors.BadRequestf("missing parameter")
|
return nil, errors.BadRequestf("missing parameter")
|
||||||
}
|
}
|
||||||
@ -19,12 +19,12 @@ func GetApiType(in models.ApiTypeName) (ApiTypeInterface, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch in {
|
switch in {
|
||||||
case models.ApiTypeName_GIN_GONIC:
|
case models.APITypeName_GIN_GONIC:
|
||||||
return gin_gonic.ApiType{}, nil
|
return gin_gonic.APIType{}, nil
|
||||||
case models.ApiTypeName_GO_SWAGGER:
|
case models.APITypeName_GO_SWAGGER:
|
||||||
return go_swagger.ApiType{}, nil
|
return go_swagger.APIType{}, nil
|
||||||
case models.ApiTypeName_MOJOLICIOUS:
|
case models.APITypeName_MOJOLICIOUS:
|
||||||
return mojolicious.ApiType{}, nil
|
return mojolicious.APIType{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.NotFoundf("Unknown Api Type")
|
return nil, errors.NotFoundf("Unknown Api Type")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package base
|
package base
|
||||||
|
|
||||||
// ApiType
|
// APIType
|
||||||
type ApiType struct {
|
type APIType struct {
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// CheckInitialize
|
// CheckInitialize
|
||||||
func (a ApiType) CheckInitialize() error {
|
func (a APIType) CheckInitialize() error {
|
||||||
|
|
||||||
return errors.NotImplementedf("CheckInitialize not implemented for %s", a.GetName())
|
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"
|
"git.home.m-and-m.ovh/mderasse/gouick/helpers/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a ApiType) GetName() models.ApiTypeName {
|
func (a APIType) GetName() models.APITypeName {
|
||||||
return models.ApiTypeName_NULL
|
return models.APITypeName_NULL
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/juju/errors"
|
"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())
|
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"
|
import "git.home.m-and-m.ovh/mderasse/gouick/helpers/api_types/base"
|
||||||
|
|
||||||
// ApiType
|
// APIType
|
||||||
type ApiType struct {
|
type APIType struct {
|
||||||
base.ApiType
|
base.APIType
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,6 @@ import (
|
|||||||
"git.home.m-and-m.ovh/mderasse/gouick/helpers/models"
|
"git.home.m-and-m.ovh/mderasse/gouick/helpers/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a ApiType) GetName() models.ApiTypeName {
|
func (a APIType) GetName() models.APITypeName {
|
||||||
return models.ApiTypeName_GIN_GONIC
|
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"
|
import "git.home.m-and-m.ovh/mderasse/gouick/helpers/api_types/base"
|
||||||
|
|
||||||
// ApiType
|
// APIType
|
||||||
type ApiType struct {
|
type APIType struct {
|
||||||
base.ApiType
|
base.APIType
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// CheckInitialize
|
// CheckInitialize
|
||||||
func (a ApiType) CheckInitialize() error {
|
func (a APIType) CheckInitialize() error {
|
||||||
|
|
||||||
log.Debugf("Starting %s check initialize", string(a.GetName()))
|
log.Debugf("Starting %s check initialize", string(a.GetName()))
|
||||||
|
|
||||||
|
@ -4,6 +4,6 @@ import (
|
|||||||
"git.home.m-and-m.ovh/mderasse/gouick/helpers/models"
|
"git.home.m-and-m.ovh/mderasse/gouick/helpers/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a ApiType) GetName() models.ApiTypeName {
|
func (a APIType) GetName() models.APITypeName {
|
||||||
return models.ApiTypeName_GO_SWAGGER
|
return models.APITypeName_GO_SWAGGER
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GetInitializeUserInput
|
// 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())
|
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"
|
import "git.home.m-and-m.ovh/mderasse/gouick/helpers/models"
|
||||||
|
|
||||||
// ApiTypeInterface
|
// APITypeInterface
|
||||||
type ApiTypeInterface interface {
|
type APITypeInterface interface {
|
||||||
CheckInitialize() error
|
CheckInitialize() error
|
||||||
GetName() models.ApiTypeName
|
GetName() models.APITypeName
|
||||||
GetInitializeUserInput(params *models.UserInputParams) (*models.UserInputParams, error)
|
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"
|
import "git.home.m-and-m.ovh/mderasse/gouick/helpers/api_types/base"
|
||||||
|
|
||||||
// ApiType
|
// APIType
|
||||||
type ApiType struct {
|
type APIType struct {
|
||||||
base.ApiType
|
base.APIType
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,6 @@ import (
|
|||||||
"git.home.m-and-m.ovh/mderasse/gouick/helpers/models"
|
"git.home.m-and-m.ovh/mderasse/gouick/helpers/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a ApiType) GetName() models.ApiTypeName {
|
func (a APIType) GetName() models.APITypeName {
|
||||||
return models.ApiTypeName_MOJOLICIOUS
|
return models.APITypeName_MOJOLICIOUS
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ func (g Golang) DescribeInstall(path string) string {
|
|||||||
commands := []string{
|
commands := []string{
|
||||||
"The following commands will be executed",
|
"The following commands will be executed",
|
||||||
fmt.Sprintf("rm -rf %s/* ", path),
|
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")
|
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)
|
log.Warnf("fail to delete content of directory %s", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadUrl := g.getDownloadUrl()
|
downloadURL := g.getDownloadURL()
|
||||||
content, err := downloadFile(downloadUrl)
|
content, err := downloadFile(downloadURL)
|
||||||
if err != nil {
|
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)
|
return errors.Trace(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ func (g Golang) Install(path string) error {
|
|||||||
|
|
||||||
err = unZip(content, "go/", path)
|
err = unZip(content, "go/", path)
|
||||||
if err != nil {
|
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)
|
return errors.Trace(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,13 +185,13 @@ func (g Golang) Install(path string) error {
|
|||||||
|
|
||||||
gzipReader, err := unGzip(content)
|
gzipReader, err := unGzip(content)
|
||||||
if err != nil {
|
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)
|
return errors.Trace(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = unTar(gzipReader, "go/", path)
|
err = unTar(gzipReader, "go/", path)
|
||||||
if err != nil {
|
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)
|
return errors.Trace(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,7 +335,7 @@ func (g Golang) GetInstallDirectory() (string, error) {
|
|||||||
return cleanOut, nil
|
return cleanOut, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g Golang) getDownloadUrl() string {
|
func (g Golang) getDownloadURL() string {
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return fmt.Sprintf("https://dl.google.com/go/go%s.%s-%s.zip", minimumGolangVersion, runtime.GOOS, runtime.GOARCH)
|
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{
|
commands := []string{
|
||||||
"The following commands will be executed",
|
"The following commands will be executed",
|
||||||
fmt.Sprintf("rm -rf %s/swagger ", path),
|
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),
|
fmt.Sprintf("chmod 644 %s/swagger", path),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,10 +156,10 @@ func (s Swagger) DescribeInstall(path string) string {
|
|||||||
// Install
|
// Install
|
||||||
func (s Swagger) Install(path string) error {
|
func (s Swagger) Install(path string) error {
|
||||||
|
|
||||||
downloadUrl := s.getDownloadUrl()
|
downloadURL := s.getDownloadURL()
|
||||||
content, err := downloadFile(downloadUrl)
|
content, err := downloadFile(downloadURL)
|
||||||
if err != nil {
|
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)
|
return errors.Trace(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ func (s Swagger) GetInstallDirectory() (string, error) {
|
|||||||
return strings.TrimSuffix(binaryPath, "/swagger"), nil
|
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)
|
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
|
// APITypeNameInput
|
||||||
func ApiTypeNameInput() models.ApiTypeName {
|
func APITypeNameInput() models.APITypeName {
|
||||||
|
|
||||||
var possibleApiTypes []string
|
var possibleAPITypes []string
|
||||||
for _, apiType := range models.GetListOfApiTypeName() {
|
for _, apiType := range models.GetListOfAPITypeName() {
|
||||||
possibleApiTypes = append(possibleApiTypes, string(apiType))
|
possibleAPITypes = append(possibleAPITypes, string(apiType))
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner := bufio.NewScanner(os.Stdin)
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
@ -122,9 +122,9 @@ func ApiTypeNameInput() models.ApiTypeName {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
apiTypeName, err := models.NewApiTypeNameFromInput(userInput)
|
apiTypeName, err := models.NewAPITypeNameFromInput(userInput)
|
||||||
if err != nil {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,28 +6,28 @@ import (
|
|||||||
"github.com/juju/errors"
|
"github.com/juju/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ApiTypeName
|
// APITypeName
|
||||||
type ApiTypeName string
|
type APITypeName string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ApiTypeName_GIN_GONIC ApiTypeName = "Gin Gonic"
|
APITypeName_GIN_GONIC APITypeName = "Gin Gonic"
|
||||||
ApiTypeName_GO_SWAGGER ApiTypeName = "Go Swagger"
|
APITypeName_GO_SWAGGER APITypeName = "Go Swagger"
|
||||||
ApiTypeName_MOJOLICIOUS ApiTypeName = "Mojolicious"
|
APITypeName_MOJOLICIOUS APITypeName = "Mojolicious"
|
||||||
ApiTypeName_NULL ApiTypeName = ""
|
APITypeName_NULL APITypeName = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetListOfApiTypeName returns a list of ApiTypeName
|
// GetListOfAPITypeName returns a list of APITypeName
|
||||||
func GetListOfApiTypeName() []ApiTypeName {
|
func GetListOfAPITypeName() []APITypeName {
|
||||||
return []ApiTypeName{
|
return []APITypeName{
|
||||||
ApiTypeName_GIN_GONIC,
|
APITypeName_GIN_GONIC,
|
||||||
ApiTypeName_GO_SWAGGER,
|
APITypeName_GO_SWAGGER,
|
||||||
ApiTypeName_MOJOLICIOUS,
|
APITypeName_MOJOLICIOUS,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValid validates enum values
|
// IsValid validates enum values
|
||||||
func (e ApiTypeName) IsValid() bool {
|
func (e APITypeName) IsValid() bool {
|
||||||
for _, v := range GetListOfApiTypeName() {
|
for _, v := range GetListOfAPITypeName() {
|
||||||
if e == v {
|
if e == v {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -36,27 +36,27 @@ func (e ApiTypeName) IsValid() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewApiTypeName(in string) (ApiTypeName, error) {
|
func NewAPITypeName(in string) (APITypeName, error) {
|
||||||
out := ApiTypeName_NULL
|
out := APITypeName_NULL
|
||||||
if in != "" {
|
if in != "" {
|
||||||
out = ApiTypeName(in)
|
out = APITypeName(in)
|
||||||
if !out.IsValid() {
|
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
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewApiTypeNameFromInput
|
// NewAPITypeNameFromInput
|
||||||
func NewApiTypeNameFromInput(in string) (ApiTypeName, error) {
|
func NewAPITypeNameFromInput(in string) (APITypeName, error) {
|
||||||
|
|
||||||
in = strings.ToLower(in)
|
in = strings.ToLower(in)
|
||||||
in = strings.ReplaceAll(in, " ", "-")
|
in = strings.ReplaceAll(in, " ", "-")
|
||||||
in = strings.ReplaceAll(in, "_", "-")
|
in = strings.ReplaceAll(in, "_", "-")
|
||||||
|
|
||||||
out := ApiTypeName_NULL
|
out := APITypeName_NULL
|
||||||
if in != "" {
|
if in != "" {
|
||||||
for _, apiTypeName := range GetListOfApiTypeName() {
|
for _, apiTypeName := range GetListOfAPITypeName() {
|
||||||
apiTypeStr := strings.ToLower(string(apiTypeName))
|
apiTypeStr := strings.ToLower(string(apiTypeName))
|
||||||
apiTypeStr = strings.ReplaceAll(apiTypeStr, " ", "-")
|
apiTypeStr = strings.ReplaceAll(apiTypeStr, " ", "-")
|
||||||
apiTypeStr = strings.ReplaceAll(apiTypeStr, "_", "-")
|
apiTypeStr = strings.ReplaceAll(apiTypeStr, "_", "-")
|
||||||
@ -64,7 +64,7 @@ func NewApiTypeNameFromInput(in string) (ApiTypeName, error) {
|
|||||||
return apiTypeName, nil
|
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
|
return out, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user