56 lines
929 B
Go
56 lines
929 B
Go
|
package enums
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"nf-repo/internal/interfaces"
|
||
|
)
|
||
|
|
||
|
type Privilege uint64
|
||
|
|
||
|
const (
|
||
|
PrivilegeUserManage Privilege = iota + 1
|
||
|
PrivilegeUpload
|
||
|
)
|
||
|
|
||
|
func (p Privilege) Value() int64 {
|
||
|
return int64(p)
|
||
|
}
|
||
|
|
||
|
func (p Privilege) Code() string {
|
||
|
switch p {
|
||
|
case PrivilegeUserManage:
|
||
|
return "user_manage"
|
||
|
case PrivilegeUpload:
|
||
|
return "image_upload"
|
||
|
default:
|
||
|
panic(fmt.Sprintf("unknown privilege: %d", p))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (p Privilege) Label() string {
|
||
|
switch p {
|
||
|
case PrivilegeUserManage:
|
||
|
return "用户管理"
|
||
|
case PrivilegeUpload:
|
||
|
return "上传镜像"
|
||
|
default:
|
||
|
panic(fmt.Sprintf("unknown privilege: %d", p))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (p Privilege) MarshalJSON() ([]byte, error) {
|
||
|
return json.Marshal(map[string]any{
|
||
|
"code": p.Code(),
|
||
|
"value": p.Value(),
|
||
|
"label": p.Label(),
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func (p Privilege) All() []interfaces.Enum {
|
||
|
return []interfaces.Enum{
|
||
|
PrivilegeUserManage,
|
||
|
PrivilegeUpload,
|
||
|
}
|
||
|
}
|