审查视图

pkg/application/role/command/role_create.go 603 字节
1 2
package command
郑周 authored
3 4 5 6
import (
	"github.com/beego/beego/v2/core/validation"
	"unicode/utf8"
)
7 8 9 10 11 12 13 14 15 16 17 18 19

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
	}
郑周 authored
20
	if utf8.RuneCountInString(in.Name) > 30 {
21 22 23 24
		validation.SetError("name", "角色名称最大长度30个字符")
		return
	}
}