feat(apiType): Start to implement apiType system
This commit is contained in:
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
|
||||
}
|
Reference in New Issue
Block a user