feat(apiType): Start to implement apiType system
This commit is contained in:
parent
66ff28f6cd
commit
ec6485aa45
14
cmd/init.go
14
cmd/init.go
@ -6,8 +6,10 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.home.m-and-m.ovh/mderasse/boot/helpers"
|
"git.home.m-and-m.ovh/mderasse/boot/helpers"
|
||||||
|
"git.home.m-and-m.ovh/mderasse/boot/helpers/api_type"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -40,7 +42,7 @@ func runInitAction(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
log.Debugf("Starting command Init")
|
log.Debugf("Starting command Init")
|
||||||
|
|
||||||
log.Debugf("Checking dependecies")
|
log.Debugf("Checking dependencies")
|
||||||
|
|
||||||
if !checkDependencies() {
|
if !checkDependencies() {
|
||||||
return
|
return
|
||||||
@ -83,6 +85,16 @@ func runInitAction(cmd *cobra.Command, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ask which API type we want to use
|
||||||
|
var possibleApiTypes []string
|
||||||
|
for _, apiType := range api_type.GetListOfApiTypeName() {
|
||||||
|
possibleApiTypes = append(possibleApiTypes, string(apiType))
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Which kind of API do you want to init (possible values: %s)", strings.Join(possibleApiTypes, ", "))
|
||||||
|
apiType := helpers.ApiTypeInput()
|
||||||
|
|
||||||
|
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
|
||||||
|
20
helpers/api_type/api_type.go
Normal file
20
helpers/api_type/api_type.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package api_type
|
||||||
|
|
||||||
|
import "github.com/juju/errors"
|
||||||
|
|
||||||
|
func GetApiType(in ApiTypeName) (ApiTypeInterface, error) {
|
||||||
|
if in == "" {
|
||||||
|
return nil, errors.BadRequestf("missing parameter")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !in.IsValid() {
|
||||||
|
return nil, errors.NotValidf("invalid parameter")
|
||||||
|
}
|
||||||
|
|
||||||
|
switch in {
|
||||||
|
case ApyTypeName_GIN_GONIC:
|
||||||
|
case ApyTypeName_GO_SWAGGER:
|
||||||
|
case ApyTypeName_MOJOLICIOUS:
|
||||||
|
}
|
||||||
|
return nil, errors.NotFoundf("Unknown Api Type")
|
||||||
|
}
|
5
helpers/api_type/base/api_type.go
Normal file
5
helpers/api_type/base/api_type.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package base
|
||||||
|
|
||||||
|
// ApiType
|
||||||
|
type ApiType struct {
|
||||||
|
}
|
69
helpers/api_type/enum.go
Normal file
69
helpers/api_type/enum.go
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package api_type
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/juju/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ApiTypeName
|
||||||
|
type ApiTypeName string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ApyTypeName_NULL ApiTypeName = ""
|
||||||
|
ApyTypeName_GO_SWAGGER ApiTypeName = "Go Swagger"
|
||||||
|
ApyTypeName_GIN_GONIC ApiTypeName = "Gin Gonic"
|
||||||
|
ApyTypeName_MOJOLICIOUS ApiTypeName = "Mojolicious"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetListOfApiTypeName returns a list of ApiTypeName
|
||||||
|
func GetListOfApiTypeName() []ApiTypeName {
|
||||||
|
return []ApiTypeName{
|
||||||
|
ApyTypeName_GO_SWAGGER,
|
||||||
|
ApyTypeName_GIN_GONIC,
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApiTypeFromInput(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
|
||||||
|
}
|
5
helpers/api_type/gin_gonic/api_type.go
Normal file
5
helpers/api_type/gin_gonic/api_type.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package base
|
||||||
|
|
||||||
|
// ApiType
|
||||||
|
type ApiType struct {
|
||||||
|
}
|
8
helpers/api_type/go_swagger/api_type.go
Normal file
8
helpers/api_type/go_swagger/api_type.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package go_swagger
|
||||||
|
|
||||||
|
import "git.home.m-and-m.ovh/mderasse/boot/helpers/api_type/base"
|
||||||
|
|
||||||
|
// ApiType
|
||||||
|
type ApiType struct {
|
||||||
|
base.ApiType
|
||||||
|
}
|
5
helpers/api_type/interface.go
Normal file
5
helpers/api_type/interface.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package api_type
|
||||||
|
|
||||||
|
// ApiTypeInterface
|
||||||
|
type ApiTypeInterface interface {
|
||||||
|
}
|
8
helpers/api_type/mojolicious/api_type.go
Normal file
8
helpers/api_type/mojolicious/api_type.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package mojolicious
|
||||||
|
|
||||||
|
import "git.home.m-and-m.ovh/mderasse/boot/helpers/api_type/base"
|
||||||
|
|
||||||
|
// ApiType
|
||||||
|
type ApiType struct {
|
||||||
|
base.ApiType
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user