dd

package
v0.0.0-...-84fae08 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2020 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultErorrFormat = "The %s field validate failed by '%s'"

Functions

func AddDataElement

func AddDataElement(d DataElement) error

func AddDomainType

func AddDomainType(domainType DomainType) error

func GetDefaultErrorMsg

func GetDefaultErrorMsg(code int) string

func GetErrorMsg

func GetErrorMsg(code int) string

func InputByDataType

func InputByDataType(name string, v interface{}) interface{}

func LoadConfig

func LoadConfig(cf string)

加载domain和dataelement 定义

func RegisterConvertorFactory

func RegisterConvertorFactory(name string, c ConvertorFactory)

func SetDictMeta

func SetDictMeta(dm DictMeta)

func SetErrorMsg

func SetErrorMsg(code int, msg string)

func Validate

func Validate(obj interface{}) []error

func ValidateByDataType

func ValidateByDataType(name string, v interface{}, dt string) error

使用指定的数据元素对值进行校验

Types

type Convertor

type Convertor interface {
	//输入转换
	Input(v interface{}) interface{}
	//输出转换
	Output(v interface{}) interface{}
}

转换器

type ConvertorFactory

type ConvertorFactory func(expr string) Convertor

转换器工厂

type DataElement

type DataElement struct {
	Code     string
	Label    string
	DataType string //所属的域元素

	Validater     validatefunction //校验器
	ValidateExpr  string           //校验表达式
	Convertor     string           //转换器
	ConvertorExpr string
	// contains filtered or unexported fields
}

数据元素

func (*DataElement) Input

func (this *DataElement) Input(v interface{}) interface{}

func (*DataElement) Output

func (this *DataElement) Output(v interface{}) interface{}

func (*DataElement) Validate

func (this *DataElement) Validate(v interface{}) (bool, int)

type DictCatalog

type DictCatalog struct {
	Code  string
	Label string
	Tip   string
	Items []DictCatalogItem
}

词条

func GetDict

func GetDict(d string) *DictCatalog

type DictCatalogItem

type DictCatalogItem struct {
	Code    string            //值
	Label   string            //显示值
	Tip     string            //提示
	Virtual bool              //是否虚拟,表示存在有同名的词条
	Ord     int               //显示次序
	Extends map[string]string //扩展属性
}

词条的选择项

type DictMeta

type DictMeta func(code string) *DictCatalog

---------------------------字典------------------------//

type DomainType

type DomainType struct {
	Code         string
	Label        string
	DataType     Type             `yaml:"type"` //数据元素
	Length       int              //最大长度
	NullEnabled  bool             `yaml:"null"` //是否允许为空
	Validater    validatefunction //校验器
	ValidateExpr string           `yaml:"expr"` //校验表达式
}

func (*DomainType) Validate

func (this *DomainType) Validate(v interface{}) (bool, int)

返回,是否校验通过及对应的错误码

type Type

type Type byte

*

基本模型
 1、base type
    字符串
    数字
    枚举
    日期
 2、领域元素
    长度,通用规则
 3、数据元素
    可以继承领域元素,设置check,convert
const (
	T_string Type = iota
	T_int
	T_date
	T_datetime
)

func (*Type) UnmarshalYAML

func (this *Type) UnmarshalYAML(unmarshal func(v interface{}) error) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL