fix: 修改多个处理函数的返回类型为指针类型,以提高内存使用效率并避免不必要的拷贝
This commit is contained in:
@@ -26,11 +26,11 @@ var userLevelMap = map[string]constants.PermissionLevel{
|
||||
"忽略": constants.LEVEL_IGNORE,
|
||||
}
|
||||
|
||||
func setUserLevel(msg model.Message) (reply model.Reply) {
|
||||
func setUserLevel(msg model.Message) (reply *model.Reply) {
|
||||
re := regexp.MustCompile(`\s+`)
|
||||
tokens := re.Split(msg.RawMsg, -1)
|
||||
if len(tokens) < 3 {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "参数不足",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -44,7 +44,7 @@ func setUserLevel(msg model.Message) (reply model.Reply) {
|
||||
log.Println(userText)
|
||||
user, err := strconv.Atoi(userText)
|
||||
if err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "用户解析失败",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -53,20 +53,20 @@ func setUserLevel(msg model.Message) (reply model.Reply) {
|
||||
levelText := tokens[2]
|
||||
level, ok := userLevelMap[levelText]
|
||||
if !ok {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "权限不存在",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
if err := auth.SetPermission(int64(user), level); err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "权限设置失败",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "权限设置成功",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
|
||||
Reference in New Issue
Block a user