move config -> internal.config and config.datatype to datatype
This commit is contained in:
parent
4e0d669029
commit
1b4922693b
|
@ -1,6 +1,6 @@
|
||||||
package builtin
|
package builtin
|
||||||
|
|
||||||
import "git.xdrm.io/go/aicra/config/datatype"
|
import "git.xdrm.io/go/aicra/datatype"
|
||||||
|
|
||||||
// AnyDataType is what its name tells
|
// AnyDataType is what its name tells
|
||||||
type AnyDataType struct{}
|
type AnyDataType struct{}
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype/builtin"
|
"git.xdrm.io/go/aicra/datatype/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAny_AvailableTypes(t *testing.T) {
|
func TestAny_AvailableTypes(t *testing.T) {
|
|
@ -1,6 +1,6 @@
|
||||||
package builtin
|
package builtin
|
||||||
|
|
||||||
import "git.xdrm.io/go/aicra/config/datatype"
|
import "git.xdrm.io/go/aicra/datatype"
|
||||||
|
|
||||||
// BoolDataType is what its name tells
|
// BoolDataType is what its name tells
|
||||||
type BoolDataType struct{}
|
type BoolDataType struct{}
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype/builtin"
|
"git.xdrm.io/go/aicra/datatype/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBool_AvailableTypes(t *testing.T) {
|
func TestBool_AvailableTypes(t *testing.T) {
|
|
@ -3,7 +3,7 @@ package builtin
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype"
|
"git.xdrm.io/go/aicra/datatype"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FloatDataType is what its name tells
|
// FloatDataType is what its name tells
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype/builtin"
|
"git.xdrm.io/go/aicra/datatype/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFloat64_AvailableTypes(t *testing.T) {
|
func TestFloat64_AvailableTypes(t *testing.T) {
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype"
|
"git.xdrm.io/go/aicra/datatype"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IntDataType is what its name tells
|
// IntDataType is what its name tells
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype/builtin"
|
"git.xdrm.io/go/aicra/datatype/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInt_AvailableTypes(t *testing.T) {
|
func TestInt_AvailableTypes(t *testing.T) {
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype"
|
"git.xdrm.io/go/aicra/datatype"
|
||||||
)
|
)
|
||||||
|
|
||||||
var fixedLengthRegex = regexp.MustCompile(`^string\((\d+)\)$`)
|
var fixedLengthRegex = regexp.MustCompile(`^string\((\d+)\)$`)
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype/builtin"
|
"git.xdrm.io/go/aicra/datatype/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestString_AvailableTypes(t *testing.T) {
|
func TestString_AvailableTypes(t *testing.T) {
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype"
|
"git.xdrm.io/go/aicra/datatype"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UintDataType is what its name tells
|
// UintDataType is what its name tells
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype/builtin"
|
"git.xdrm.io/go/aicra/datatype/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUint_AvailableTypes(t *testing.T) {
|
func TestUint_AvailableTypes(t *testing.T) {
|
|
@ -4,9 +4,9 @@ package datatype
|
||||||
// and casts the value into a compatible type
|
// and casts the value into a compatible type
|
||||||
type Validator func(value interface{}) (cast interface{}, valid bool)
|
type Validator func(value interface{}) (cast interface{}, valid bool)
|
||||||
|
|
||||||
// DataType builds a DataType from the type definition (from the
|
// T builds a T from the type definition (from the
|
||||||
// configuration field "type") and returns NIL if the type
|
// configuration field "type") and returns NIL if the type
|
||||||
// definition does not match this DataType
|
// definition does not match this T
|
||||||
type DataType interface {
|
type T interface {
|
||||||
Build(typeDefinition string) Validator
|
Build(typeDefinition string) Validator
|
||||||
}
|
}
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype/builtin"
|
"git.xdrm.io/go/aicra/datatype/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLegalServiceName(t *testing.T) {
|
func TestLegalServiceName(t *testing.T) {
|
|
@ -1,6 +1,6 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import "git.xdrm.io/go/aicra/config/datatype"
|
import "git.xdrm.io/go/aicra/datatype"
|
||||||
|
|
||||||
func (param *Parameter) checkAndFormat() error {
|
func (param *Parameter) checkAndFormat() error {
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func (param *Parameter) checkAndFormat() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// assigns the first matching data type from the type definition
|
// assigns the first matching data type from the type definition
|
||||||
func (param *Parameter) assignDataType(types []datatype.DataType) bool {
|
func (param *Parameter) assignDataType(types []datatype.T) bool {
|
||||||
for _, dtype := range types {
|
for _, dtype := range types {
|
||||||
param.Validator = dtype.Build(param.Type)
|
param.Validator = dtype.Build(param.Type)
|
||||||
if param.Validator != nil {
|
if param.Validator != nil {
|
|
@ -7,14 +7,14 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype"
|
"git.xdrm.io/go/aicra/datatype"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parse builds a server configuration from a json reader and checks for most format errors.
|
// Parse builds a server configuration from a json reader and checks for most format errors.
|
||||||
// you can provide additional DataTypes as variadic arguments
|
// you can provide additional DataTypes as variadic arguments
|
||||||
func Parse(r io.Reader, dtypes ...datatype.DataType) (*Server, error) {
|
func Parse(r io.Reader, dtypes ...datatype.T) (*Server, error) {
|
||||||
server := &Server{
|
server := &Server{
|
||||||
Types: make([]datatype.DataType, 0),
|
Types: make([]datatype.T, 0),
|
||||||
Services: make([]*Service, 0),
|
Services: make([]*Service, 0),
|
||||||
}
|
}
|
||||||
// add data types
|
// add data types
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype"
|
"git.xdrm.io/go/aicra/datatype"
|
||||||
)
|
)
|
||||||
|
|
||||||
var braceRegex = regexp.MustCompile(`^{([a-z_-]+)}$`)
|
var braceRegex = regexp.MustCompile(`^{([a-z_-]+)}$`)
|
||||||
|
@ -86,7 +86,7 @@ func (svc *Service) checkPattern() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *Service) checkAndFormatInput(types []datatype.DataType) error {
|
func (svc *Service) checkAndFormatInput(types []datatype.T) error {
|
||||||
|
|
||||||
// ignore no parameter
|
// ignore no parameter
|
||||||
if svc.Input == nil || len(svc.Input) < 1 {
|
if svc.Input == nil || len(svc.Input) < 1 {
|
|
@ -3,14 +3,14 @@ package config
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/config/datatype"
|
"git.xdrm.io/go/aicra/datatype"
|
||||||
)
|
)
|
||||||
|
|
||||||
var availableHTTPMethods = []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete}
|
var availableHTTPMethods = []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete}
|
||||||
|
|
||||||
// Server represents a full server configuration
|
// Server represents a full server configuration
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Types []datatype.DataType
|
Types []datatype.T
|
||||||
Services []*Service
|
Services []*Service
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue