2024-09-18 05:19:10 +08:00
|
|
|
|
package common
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"encoding/json"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var UserUsableGroups = map[string]string{
|
|
|
|
|
|
"default": "默认分组",
|
|
|
|
|
|
"vip": "vip分组",
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func UserUsableGroups2JSONString() string {
|
|
|
|
|
|
jsonBytes, err := json.Marshal(UserUsableGroups)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
SysError("error marshalling user groups: " + err.Error())
|
|
|
|
|
|
}
|
|
|
|
|
|
return string(jsonBytes)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func UpdateUserUsableGroupsByJSONString(jsonStr string) error {
|
|
|
|
|
|
UserUsableGroups = make(map[string]string)
|
|
|
|
|
|
return json.Unmarshal([]byte(jsonStr), &UserUsableGroups)
|
|
|
|
|
|
}
|
2024-10-10 13:39:09 +08:00
|
|
|
|
|
2024-10-14 16:15:10 +08:00
|
|
|
|
func GetUserUsableGroups(userGroup string) map[string]string {
|
|
|
|
|
|
if userGroup == "" {
|
|
|
|
|
|
// 如果userGroup为空,返回UserUsableGroups
|
|
|
|
|
|
return UserUsableGroups
|
|
|
|
|
|
}
|
|
|
|
|
|
// 如果userGroup不在UserUsableGroups中,返回UserUsableGroups + userGroup
|
|
|
|
|
|
if _, ok := UserUsableGroups[userGroup]; !ok {
|
|
|
|
|
|
appendUserUsableGroups := make(map[string]string)
|
|
|
|
|
|
for k, v := range UserUsableGroups {
|
|
|
|
|
|
appendUserUsableGroups[k] = v
|
|
|
|
|
|
}
|
|
|
|
|
|
appendUserUsableGroups[userGroup] = "用户分组"
|
|
|
|
|
|
return appendUserUsableGroups
|
|
|
|
|
|
}
|
|
|
|
|
|
// 如果userGroup在UserUsableGroups中,返回UserUsableGroups
|
|
|
|
|
|
return UserUsableGroups
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-10 13:39:09 +08:00
|
|
|
|
func GroupInUserUsableGroups(groupName string) bool {
|
|
|
|
|
|
_, ok := UserUsableGroups[groupName]
|
|
|
|
|
|
return ok
|
|
|
|
|
|
}
|