fix(clean): Fix import order, func name, ...
This commit is contained in:
parent
f7e9aa7dfb
commit
a3c953c7a4
10
cmd/init.go
10
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, ", "))
|
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:
|
// XXX:
|
||||||
// Check we are in gopath or ask for the gomod name
|
// Check we are in gopath or ask for the gomod name
|
||||||
// Create directory
|
// Create directory
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
package api_type
|
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) {
|
func GetApiType(in ApiTypeName) (ApiTypeInterface, error) {
|
||||||
if in == "" {
|
if in == "" {
|
||||||
@ -13,8 +19,12 @@ func GetApiType(in ApiTypeName) (ApiTypeInterface, error) {
|
|||||||
|
|
||||||
switch in {
|
switch in {
|
||||||
case ApyTypeName_GIN_GONIC:
|
case ApyTypeName_GIN_GONIC:
|
||||||
|
return gin_gonic.ApiType{}, nil
|
||||||
case ApyTypeName_GO_SWAGGER:
|
case ApyTypeName_GO_SWAGGER:
|
||||||
|
return go_swagger.ApiType{}, nil
|
||||||
case ApyTypeName_MOJOLICIOUS:
|
case ApyTypeName_MOJOLICIOUS:
|
||||||
|
return mojolicious.ApiType{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.NotFoundf("Unknown Api Type")
|
return nil, errors.NotFoundf("Unknown Api Type")
|
||||||
}
|
}
|
||||||
|
@ -10,17 +10,17 @@ import (
|
|||||||
type ApiTypeName string
|
type ApiTypeName string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ApyTypeName_NULL ApiTypeName = ""
|
|
||||||
ApyTypeName_GO_SWAGGER ApiTypeName = "Go Swagger"
|
|
||||||
ApyTypeName_GIN_GONIC ApiTypeName = "Gin Gonic"
|
ApyTypeName_GIN_GONIC ApiTypeName = "Gin Gonic"
|
||||||
|
ApyTypeName_GO_SWAGGER ApiTypeName = "Go Swagger"
|
||||||
ApyTypeName_MOJOLICIOUS ApiTypeName = "Mojolicious"
|
ApyTypeName_MOJOLICIOUS ApiTypeName = "Mojolicious"
|
||||||
|
ApyTypeName_NULL ApiTypeName = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetListOfApiTypeName returns a list of ApiTypeName
|
// GetListOfApiTypeName returns a list of ApiTypeName
|
||||||
func GetListOfApiTypeName() []ApiTypeName {
|
func GetListOfApiTypeName() []ApiTypeName {
|
||||||
return []ApiTypeName{
|
return []ApiTypeName{
|
||||||
ApyTypeName_GO_SWAGGER,
|
|
||||||
ApyTypeName_GIN_GONIC,
|
ApyTypeName_GIN_GONIC,
|
||||||
|
ApyTypeName_GO_SWAGGER,
|
||||||
ApyTypeName_MOJOLICIOUS,
|
ApyTypeName_MOJOLICIOUS,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,7 +47,8 @@ func NewApiTypeName(in string) (ApiTypeName, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewApiTypeFromInput(in string) (ApiTypeName, error) {
|
// NewApiTypeNameFromInput
|
||||||
|
func NewApiTypeNameFromInput(in string) (ApiTypeName, error) {
|
||||||
|
|
||||||
in = strings.ToLower(in)
|
in = strings.ToLower(in)
|
||||||
in = strings.ReplaceAll(in, " ", "-")
|
in = strings.ReplaceAll(in, " ", "-")
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package base
|
package gin_gonic
|
||||||
|
|
||||||
|
import "git.home.m-and-m.ovh/mderasse/boot/helpers/api_type/base"
|
||||||
|
|
||||||
// ApiType
|
// ApiType
|
||||||
type ApiType struct {
|
type ApiType struct {
|
||||||
|
base.ApiType
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.home.m-and-m.ovh/mderasse/boot/helpers/api_type"
|
"git.home.m-and-m.ovh/mderasse/boot/helpers/api_type"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -54,8 +55,8 @@ func PathInput() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApiTypeInput
|
// ApiTypeNameInput
|
||||||
func ApiTypeInput() api_type.ApiTypeName {
|
func ApiTypeNameInput() api_type.ApiTypeName {
|
||||||
|
|
||||||
var possibleApiTypes []string
|
var possibleApiTypes []string
|
||||||
for _, apiType := range api_type.GetListOfApiTypeName() {
|
for _, apiType := range api_type.GetListOfApiTypeName() {
|
||||||
@ -68,7 +69,7 @@ func ApiTypeInput() api_type.ApiTypeName {
|
|||||||
scanner.Scan()
|
scanner.Scan()
|
||||||
userInput := scanner.Text()
|
userInput := scanner.Text()
|
||||||
|
|
||||||
apiTypeName, err := api_type.NewApiTypeFromInput(userInput)
|
apiTypeName, err := api_type.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
|
||||||
|
Loading…
Reference in New Issue
Block a user