package command import ( "github.com/beego/beego/v2/core/validation" "unicode/utf8" ) type UpdateRoleCommand struct { CompanyId int64 `cname:"公司ID" json:"companyId"` Id int64 `cname:"角色ID" json:"id,string" valid:"Required"` Name string `cname:"角色名称" json:"name" valid:"Required"` Description string `cname:"角色描述" json:"description"` } func (in *UpdateRoleCommand) Valid(validation *validation.Validation) { if in.CompanyId == 0 { validation.SetError("companyId", "公司ID无效") } if utf8.RuneCountInString(in.Name) > 30 { validation.SetError("name", "角色名称最大长度30个字符") return } }