package rule import ( "encoding/json" "git.sxidc.com/go-framework/baize/framework/core/domain" "git.sxidc.com/go-framework/baize/framework/core/domain/entity" "github.com/pkg/errors" ) const ( FieldScope = "Scope" FieldDomainName = "DomainName" FieldRule = "Rule" FieldEnabled = "Enabled" ) var ( ColumnScope = domain.ColumnName(FieldScope) ColumnDomainName = domain.ColumnName(FieldDomainName) ColumnRule = domain.ColumnName(FieldRule) ColumnEnabled = domain.ColumnName(FieldEnabled) ) var fieldMap = map[string]string{ FieldScope: "范围", FieldDomainName: "领域名", FieldRule: "规则", } type Entity struct { entity.Base Scope string `sqlmapping:"column:scope;notUpdate;" sqlresult:"column:scope;" check:"required,lte=256,when=create"` DomainName string `sqlmapping:"column:domain_name;notUpdate;" sqlresult:"column:domain_name;" check:"required,lte=256,when=create"` Rule string `sqlmapping:"column:rule;notUpdate;" sqlresult:"column:rule;" check:"required,when=create"` Enabled bool `sqlresult:"column:enabled;" sqlresult:"column:enabled;"` } func (e *Entity) DomainCNName() string { return "查询规则" } func (e *Entity) DomainCamelName() string { return "QueryRule" } func (e *Entity) GetFieldMap() map[string]string { return fieldMap } func (e *Entity) LintRule() error { r := new(Rule) err := json.Unmarshal([]byte(e.Rule), r) if err != nil { return errors.New(err.Error()) } return r.check() }