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