package configuration import ( "git.sxidc.com/go-tools/utils/strutils" "git.sxidc.com/service-supports/fserr" ) const ( TableName = "test.configurations" ) const ( ColumnGroup = "group" ColumnValue = "value" ) const ( domainCNName = "配置" ) const ( fieldGroupMaxLen = 256 fieldValueMaxLen = 256 ) type Entity struct { Group string `sqlmapping:"column:group;key;notUpdate;" sqlresult:"column:group;"` Value string `sqlmapping:"column:value;notUpdate;" sqlresult:"column:value;"` } func (e *Entity) DomainCNName() string { return domainCNName } func (e *Entity) CheckKeyFields() error { return e.checkFieldGroup() } func (e *Entity) ForCreate() error { err := e.checkFieldGroup() if err != nil { return err } err = e.checkFieldValue() if err != nil { return err } return nil } func (e *Entity) checkFieldGroup() error { if strutils.IsStringEmpty(e.Group) { return fserr.New(domainCNName + "组为空") } if len(e.Group) > fieldGroupMaxLen { return fserr.New(domainCNName + "组超出限定长度") } return nil } func (e *Entity) checkFieldValue() error { if strutils.IsStringEmpty(e.Value) { return fserr.New(domainCNName + "值为空") } if len([]byte(e.Value)) > fieldValueMaxLen { return fserr.New(domainCNName + "值超出限定长度") } return nil }