refactor: upgrade to Go 1.26 and modernize code idioms
- Replace `interface{}` with `any` type alias across all packages
- Use built-in `min()`/`max()` for parameter clamping
- Use `slices.SortFunc`, `slices.Min`, `slices.Max` for cleaner code
- Use `strings.Cut()` for simpler string parsing in auth middleware
- Use `errors.Is()` for proper error comparison in handlers
- Update dependencies: golang.org/x/image 0.37.0 -> 0.38.0
- Add Wire code generation guidelines to ARCHITECTURE.md
- Disable Go cache in CI build workflow
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -90,7 +91,7 @@ func (h *GroupHandler) GetGroup(c *gin.Context) {
|
||||
|
||||
group, err := h.groupService.GetGroupByID(groupID)
|
||||
if err != nil {
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -129,7 +130,7 @@ func (h *GroupHandler) UpdateGroup(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
updates := make(map[string]interface{})
|
||||
updates := make(map[string]any)
|
||||
if req.Name != "" {
|
||||
updates["name"] = req.Name
|
||||
}
|
||||
@@ -145,7 +146,7 @@ func (h *GroupHandler) UpdateGroup(c *gin.Context) {
|
||||
response.Forbidden(c, "没有权限修改群组信息")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -178,7 +179,7 @@ func (h *GroupHandler) DissolveGroup(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主可以解散群组")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -215,7 +216,7 @@ func (h *GroupHandler) TransferOwner(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主可以转让群主")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -279,7 +280,7 @@ func (h *GroupHandler) InviteMembers(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群成员可以邀请他人")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -314,7 +315,7 @@ func (h *GroupHandler) JoinGroup(c *gin.Context) {
|
||||
response.Forbidden(c, "该群不允许加入")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -353,7 +354,7 @@ func (h *GroupHandler) LeaveGroup(c *gin.Context) {
|
||||
response.BadRequest(c, "不是群成员")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -390,7 +391,7 @@ func (h *GroupHandler) RemoveMember(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主或管理员可以移除成员")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -429,7 +430,7 @@ func (h *GroupHandler) GetMembers(c *gin.Context) {
|
||||
|
||||
members, total, err := h.groupService.GetMembers(groupID, page, pageSize)
|
||||
if err != nil {
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -517,7 +518,7 @@ func (h *GroupHandler) HandleGetMyMemberInfo(c *gin.Context) {
|
||||
// 获取群组信息
|
||||
group, err := h.groupService.GetGroupByID(groupID)
|
||||
if err != nil {
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -542,7 +543,7 @@ func (h *GroupHandler) HandleGetMyMemberInfo(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 添加群组禁言状态信息
|
||||
response.Success(c, map[string]interface{}{
|
||||
response.Success(c, map[string]any{
|
||||
"member": memberResp,
|
||||
"mute_all": group.MuteAll,
|
||||
"is_muted": member.Muted || group.MuteAll,
|
||||
@@ -570,7 +571,7 @@ func (h *GroupHandler) HandleDissolveGroup(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主可以解散群组")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -612,7 +613,7 @@ func (h *GroupHandler) HandleTransferOwner(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主可以转让群主")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -657,7 +658,7 @@ func (h *GroupHandler) HandleInviteMembers(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主或管理员可以邀请他人")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -696,7 +697,7 @@ func (h *GroupHandler) HandleJoinGroup(c *gin.Context) {
|
||||
response.Forbidden(c, "该群不允许加入")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -741,7 +742,7 @@ func (h *GroupHandler) HandleSetNickname(c *gin.Context) {
|
||||
response.BadRequest(c, "不是群成员")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -778,7 +779,7 @@ func (h *GroupHandler) HandleSetJoinType(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主可以设置加群方式")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -824,7 +825,7 @@ func (h *GroupHandler) HandleCreateAnnouncement(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主或管理员可以发布公告")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -855,7 +856,7 @@ func (h *GroupHandler) HandleGetAnnouncements(c *gin.Context) {
|
||||
|
||||
announcements, total, err := h.groupService.GetAnnouncements(groupID, page, pageSize)
|
||||
if err != nil {
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -916,7 +917,7 @@ func (h *GroupHandler) GetMyMemberInfo(c *gin.Context) {
|
||||
// 获取群组信息
|
||||
group, err := h.groupService.GetGroupByID(groupID)
|
||||
if err != nil {
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -941,7 +942,7 @@ func (h *GroupHandler) GetMyMemberInfo(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 添加群组禁言状态信息
|
||||
response.Success(c, map[string]interface{}{
|
||||
response.Success(c, map[string]any{
|
||||
"member": memberResp,
|
||||
"mute_all": group.MuteAll,
|
||||
"is_muted": member.Muted || group.MuteAll,
|
||||
@@ -981,7 +982,7 @@ func (h *GroupHandler) SetMemberRole(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主可以设置成员角色")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1022,7 +1023,7 @@ func (h *GroupHandler) SetNickname(c *gin.Context) {
|
||||
response.BadRequest(c, "不是群成员")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1065,7 +1066,7 @@ func (h *GroupHandler) MuteMember(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主或管理员可以禁言成员")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1116,7 +1117,7 @@ func (h *GroupHandler) SetMuteAll(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主可以设置全员禁言")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1157,7 +1158,7 @@ func (h *GroupHandler) SetJoinType(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主可以设置加群方式")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1205,7 +1206,7 @@ func (h *GroupHandler) CreateAnnouncement(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主或管理员可以发布公告")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1236,7 +1237,7 @@ func (h *GroupHandler) GetAnnouncements(c *gin.Context) {
|
||||
|
||||
announcements, total, err := h.groupService.GetAnnouncements(groupID, page, pageSize)
|
||||
if err != nil {
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1363,7 +1364,7 @@ func (h *GroupHandler) GetMembersByCursor(c *gin.Context) {
|
||||
// 调用游标分页服务
|
||||
result, err := h.groupService.GetMembersByCursor(c.Request.Context(), groupID, req)
|
||||
if err != nil {
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1406,7 +1407,7 @@ func (h *GroupHandler) GetAnnouncementsByCursor(c *gin.Context) {
|
||||
// 调用游标分页服务
|
||||
result, err := h.groupService.GetAnnouncementsByCursor(c.Request.Context(), groupID, req)
|
||||
if err != nil {
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1472,7 +1473,7 @@ func (h *GroupHandler) HandleSetGroupKick(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主或管理员可以移除成员")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1543,7 +1544,7 @@ func (h *GroupHandler) HandleSetGroupBan(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主或管理员可以禁言成员")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1593,7 +1594,7 @@ func (h *GroupHandler) HandleSetGroupWholeBan(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主可以设置全员禁言")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1646,7 +1647,7 @@ func (h *GroupHandler) HandleSetGroupAdmin(c *gin.Context) {
|
||||
response.Forbidden(c, "只有群主可以设置管理员")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1691,7 +1692,7 @@ func (h *GroupHandler) HandleSetGroupName(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
updates := map[string]interface{}{
|
||||
updates := map[string]any{
|
||||
"name": params.GroupName,
|
||||
}
|
||||
|
||||
@@ -1701,7 +1702,7 @@ func (h *GroupHandler) HandleSetGroupName(c *gin.Context) {
|
||||
response.Forbidden(c, "没有权限修改群组信息")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1740,7 +1741,7 @@ func (h *GroupHandler) HandleSetGroupAvatar(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
updates := map[string]interface{}{
|
||||
updates := map[string]any{
|
||||
"avatar": params.Avatar,
|
||||
}
|
||||
|
||||
@@ -1750,7 +1751,7 @@ func (h *GroupHandler) HandleSetGroupAvatar(c *gin.Context) {
|
||||
response.Forbidden(c, "没有权限修改群组信息")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1784,7 +1785,7 @@ func (h *GroupHandler) HandleSetGroupLeave(c *gin.Context) {
|
||||
response.BadRequest(c, "不是群成员")
|
||||
return
|
||||
}
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1907,7 +1908,7 @@ func (h *GroupHandler) HandleGetGroupInfo(c *gin.Context) {
|
||||
|
||||
group, err := h.groupService.GetGroupByID(groupID)
|
||||
if err != nil {
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
@@ -1945,7 +1946,7 @@ func (h *GroupHandler) HandleGetGroupMemberList(c *gin.Context) {
|
||||
|
||||
members, total, err := h.groupService.GetMembers(groupID, page, pageSize)
|
||||
if err != nil {
|
||||
if err == service.ErrGroupNotFound {
|
||||
if errors.Is(err, service.ErrGroupNotFound) {
|
||||
response.NotFound(c, "群组不存在")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user