2020-03-14 14:24:17 +00:00
|
|
|
package config
|
|
|
|
|
2020-03-16 08:20:00 +00:00
|
|
|
import "git.xdrm.io/go/aicra/datatype"
|
2020-03-14 23:27:54 +00:00
|
|
|
|
2020-03-14 14:24:17 +00:00
|
|
|
func (param *Parameter) checkAndFormat() error {
|
|
|
|
|
|
|
|
// missing description
|
|
|
|
if len(param.Description) < 1 {
|
|
|
|
return ErrMissingParamDesc
|
|
|
|
}
|
|
|
|
|
|
|
|
// invalid type
|
|
|
|
if len(param.Type) < 1 || param.Type == "?" {
|
|
|
|
return ErrMissingParamType
|
|
|
|
}
|
|
|
|
|
|
|
|
// set optional + type
|
|
|
|
if param.Type[0] == '?' {
|
|
|
|
param.Optional = true
|
|
|
|
param.Type = param.Type[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-03-14 23:27:54 +00:00
|
|
|
|
|
|
|
// assigns the first matching data type from the type definition
|
2020-03-16 08:20:00 +00:00
|
|
|
func (param *Parameter) assignDataType(types []datatype.T) bool {
|
2020-03-14 23:27:54 +00:00
|
|
|
for _, dtype := range types {
|
2020-03-22 15:50:10 +00:00
|
|
|
param.Validator = dtype.Build(param.Type, types...)
|
2020-03-14 23:27:54 +00:00
|
|
|
if param.Validator != nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|