admin_permission.go 880 字节
package domain

//权限代码
const (
	PERMINSSION_ADMIN_USER string = "ADMIN_USER"
	PERMINSSION_PARTNER    string = "PARTNER"
)

//权限数据
var ConstAdminPermissions = map[string]AdminPermission{
	PERMINSSION_ADMIN_USER: AdminPermission{
		Code: PERMINSSION_ADMIN_USER,
		Name: "管理员管理",
	},
	PERMINSSION_PARTNER: AdminPermission{
		Code: PERMINSSION_PARTNER,
		Name: "合伙人管理",
	},
}

// 权限结构
type AdminPermission struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

func (permission AdminPermission) GetPermissions(codes []string) []AdminPermission {
	newPermissions := []AdminPermission{}
	if len(codes) == 0 {
		return newPermissions
	}
	for i := range codes {
		code := codes[i]
		if _, ok := ConstAdminPermissions[code]; ok {
			newPermissions = append(newPermissions, ConstAdminPermissions[code])
		}
	}
	return newPermissions
}