feat(init): Get User input for config + small refacto

This commit is contained in:
Matthieu 'JP' DERASSE
2022-08-01 19:47:46 +00:00
parent 13903329c8
commit 9103e7ba60
24 changed files with 314 additions and 86 deletions

View File

@ -0,0 +1,7 @@
package models
// UserInputParams
type UserInputParams struct {
GoModuleName *string
DB bool
}

View File

@ -0,0 +1,70 @@
package models
import (
"strings"
"github.com/juju/errors"
)
// ApiTypeName
type ApiTypeName string
const (
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_GIN_GONIC,
ApyTypeName_GO_SWAGGER,
ApyTypeName_MOJOLICIOUS,
}
}
// IsValid validates enum values
func (e ApiTypeName) IsValid() bool {
for _, v := range GetListOfApiTypeName() {
if e == v {
return true
}
}
return false
}
func NewApiTypeName(in string) (ApiTypeName, error) {
out := ApyTypeName_NULL
if in != "" {
out = ApiTypeName(in)
if !out.IsValid() {
return ApyTypeName_NULL, errors.BadRequestf("Value %s invalid for enum ApiTypeName", in)
}
}
return out, nil
}
// NewApiTypeNameFromInput
func NewApiTypeNameFromInput(in string) (ApiTypeName, error) {
in = strings.ToLower(in)
in = strings.ReplaceAll(in, " ", "-")
in = strings.ReplaceAll(in, "_", "-")
out := ApyTypeName_NULL
if in != "" {
for _, apiTypeName := range GetListOfApiTypeName() {
apiTypeStr := strings.ToLower(string(apiTypeName))
apiTypeStr = strings.ReplaceAll(apiTypeStr, " ", "-")
apiTypeStr = strings.ReplaceAll(apiTypeStr, "_", "-")
if in == apiTypeStr {
return apiTypeName, nil
}
}
return ApyTypeName_NULL, errors.BadRequestf("Value %s invalid for enum ApiTypeName", in)
}
return out, nil
}

View File

@ -0,0 +1,10 @@
package models
// DependencyName
type DependencyName string
const (
DependencyName_GIT DependencyName = "Git"
DependencyName_GOLANG DependencyName = "Golang"
DependencyName_GO_SWAGGER DependencyName = "Go Swagger"
)