Skip to content

Commit

Permalink
rpc add return line number log
Browse files Browse the repository at this point in the history
  • Loading branch information
withchao committed Jul 7, 2023
1 parent 85b584a commit dd5e1d0
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/rpc/admin/applet.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package admin

import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"strings"
"time"

Expand All @@ -31,6 +32,7 @@ import (
)

func (o *adminServer) AddApplet(ctx context.Context, req *admin.AddAppletReq) (*admin.AddAppletResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down Expand Up @@ -66,6 +68,7 @@ func (o *adminServer) AddApplet(ctx context.Context, req *admin.AddAppletReq) (*
}

func (o *adminServer) DelApplet(ctx context.Context, req *admin.DelAppletReq) (*admin.DelAppletResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand All @@ -86,6 +89,7 @@ func (o *adminServer) DelApplet(ctx context.Context, req *admin.DelAppletReq) (*
}

func (o *adminServer) UpdateApplet(ctx context.Context, req *admin.UpdateAppletReq) (*admin.UpdateAppletResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand All @@ -104,6 +108,7 @@ func (o *adminServer) UpdateApplet(ctx context.Context, req *admin.UpdateAppletR
}

func (o *adminServer) FindApplet(ctx context.Context, req *admin.FindAppletReq) (*admin.FindAppletResp, error) {
defer log.ZDebug(ctx, "return")
if _, _, err := mctx.Check(ctx); err != nil {
return nil, err
}
Expand Down Expand Up @@ -131,6 +136,7 @@ func (o *adminServer) FindApplet(ctx context.Context, req *admin.FindAppletReq)
}

func (o *adminServer) SearchApplet(ctx context.Context, req *admin.SearchAppletReq) (*admin.SearchAppletResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions internal/rpc/admin/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ package admin
import (
"context"
"fmt"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"

"github.com/OpenIMSDK/chat/pkg/common/db/dbutil"
"github.com/OpenIMSDK/chat/pkg/eerrs"
"github.com/OpenIMSDK/chat/pkg/proto/admin"
)

func (o *adminServer) CheckRegisterForbidden(ctx context.Context, req *admin.CheckRegisterForbiddenReq) (*admin.CheckRegisterForbiddenResp, error) {
defer log.ZDebug(ctx, "return")
forbiddens, err := o.Database.FindIPForbidden(ctx, []string{req.Ip})
if err != nil {
return nil, err
Expand All @@ -37,6 +39,7 @@ func (o *adminServer) CheckRegisterForbidden(ctx context.Context, req *admin.Che
}

func (o *adminServer) CheckLoginForbidden(ctx context.Context, req *admin.CheckLoginForbiddenReq) (*admin.CheckLoginForbiddenResp, error) {
defer log.ZDebug(ctx, "return")
forbiddens, err := o.Database.FindIPForbidden(ctx, []string{req.Ip})
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions internal/rpc/admin/client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package admin

import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"

"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"

Expand All @@ -24,6 +25,7 @@ import (
)

func (o *adminServer) GetClientConfig(ctx context.Context, req *admin.GetClientConfigReq) (*admin.GetClientConfigResp, error) {
defer log.ZDebug(ctx, "return")
conf, err := o.Database.GetConfig(ctx)
if err != nil {
return nil, err
Expand All @@ -32,6 +34,7 @@ func (o *adminServer) GetClientConfig(ctx context.Context, req *admin.GetClientC
}

func (o *adminServer) SetClientConfig(ctx context.Context, req *admin.SetClientConfigReq) (*admin.SetClientConfigResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down
7 changes: 7 additions & 0 deletions internal/rpc/admin/invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package admin

import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"math/rand"
"strings"
"time"
Expand All @@ -31,6 +32,7 @@ import (
)

func (o *adminServer) AddInvitationCode(ctx context.Context, req *admin.AddInvitationCodeReq) (*admin.AddInvitationCodeResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down Expand Up @@ -64,6 +66,7 @@ func (o *adminServer) AddInvitationCode(ctx context.Context, req *admin.AddInvit
}

func (o *adminServer) GenInvitationCode(ctx context.Context, req *admin.GenInvitationCodeReq) (*admin.GenInvitationCodeResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down Expand Up @@ -107,6 +110,7 @@ func (o *adminServer) GenInvitationCode(ctx context.Context, req *admin.GenInvit
}

func (o *adminServer) FindInvitationCode(ctx context.Context, req *admin.FindInvitationCodeReq) (*admin.FindInvitationCodeResp, error) {
defer log.ZDebug(ctx, "return")
if _, _, err := mctx.Check(ctx); err != nil {
return nil, err
}
Expand Down Expand Up @@ -140,6 +144,7 @@ func (o *adminServer) FindInvitationCode(ctx context.Context, req *admin.FindInv
}

func (o *adminServer) UseInvitationCode(ctx context.Context, req *admin.UseInvitationCodeReq) (*admin.UseInvitationCodeResp, error) {
defer log.ZDebug(ctx, "return")
if _, _, err := mctx.Check(ctx); err != nil {
return nil, err
}
Expand All @@ -160,6 +165,7 @@ func (o *adminServer) UseInvitationCode(ctx context.Context, req *admin.UseInvit
}

func (o *adminServer) DelInvitationCode(ctx context.Context, req *admin.DelInvitationCodeReq) (*admin.DelInvitationCodeResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand All @@ -184,6 +190,7 @@ func (o *adminServer) DelInvitationCode(ctx context.Context, req *admin.DelInvit
}

func (o *adminServer) SearchInvitationCode(ctx context.Context, req *admin.SearchInvitationCodeReq) (*admin.SearchInvitationCodeResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions internal/rpc/admin/ip_forbidden.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package admin

import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"time"

admin2 "github.com/OpenIMSDK/chat/pkg/common/db/table/admin"
Expand All @@ -24,6 +25,7 @@ import (
)

func (o *adminServer) SearchIPForbidden(ctx context.Context, req *admin.SearchIPForbiddenReq) (*admin.SearchIPForbiddenResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand All @@ -47,6 +49,7 @@ func (o *adminServer) SearchIPForbidden(ctx context.Context, req *admin.SearchIP
}

func (o *adminServer) AddIPForbidden(ctx context.Context, req *admin.AddIPForbiddenReq) (*admin.AddIPForbiddenResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand All @@ -67,6 +70,7 @@ func (o *adminServer) AddIPForbidden(ctx context.Context, req *admin.AddIPForbid
}

func (o *adminServer) DelIPForbidden(ctx context.Context, req *admin.DelIPForbiddenReq) (*admin.DelIPForbiddenResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions internal/rpc/admin/register_add_friend.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package admin

import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"strings"
"time"

Expand All @@ -29,6 +30,7 @@ import (
)

func (o *adminServer) AddDefaultFriend(ctx context.Context, req *admin.AddDefaultFriendReq) (*admin.AddDefaultFriendResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down Expand Up @@ -67,6 +69,7 @@ func (o *adminServer) AddDefaultFriend(ctx context.Context, req *admin.AddDefaul
}

func (o *adminServer) DelDefaultFriend(ctx context.Context, req *admin.DelDefaultFriendReq) (*admin.DelDefaultFriendResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down Expand Up @@ -98,6 +101,7 @@ func (o *adminServer) DelDefaultFriend(ctx context.Context, req *admin.DelDefaul
}

func (o *adminServer) FindDefaultFriend(ctx context.Context, req *admin.FindDefaultFriendReq) (*admin.FindDefaultFriendResp, error) {
defer log.ZDebug(ctx, "return")
if _, _, err := mctx.Check(ctx); err != nil {
return nil, err
}
Expand All @@ -109,6 +113,7 @@ func (o *adminServer) FindDefaultFriend(ctx context.Context, req *admin.FindDefa
}

func (o *adminServer) SearchDefaultFriend(ctx context.Context, req *admin.SearchDefaultFriendReq) (*admin.SearchDefaultFriendResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion internal/rpc/admin/register_add_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
)

func (o *adminServer) AddDefaultGroup(ctx context.Context, req *admin.AddDefaultGroupReq) (*admin.AddDefaultGroupResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down Expand Up @@ -68,6 +69,7 @@ func (o *adminServer) AddDefaultGroup(ctx context.Context, req *admin.AddDefault
}

func (o *adminServer) DelDefaultGroup(ctx context.Context, req *admin.DelDefaultGroupReq) (*admin.DelDefaultGroupResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down Expand Up @@ -99,6 +101,7 @@ func (o *adminServer) DelDefaultGroup(ctx context.Context, req *admin.DelDefault
}

func (o *adminServer) FindDefaultGroup(ctx context.Context, req *admin.FindDefaultGroupReq) (*admin.FindDefaultGroupResp, error) {
defer log.ZDebug(ctx, "return")
if _, _, err := mctx.Check(ctx); err != nil {
return nil, err
}
Expand All @@ -110,7 +113,7 @@ func (o *adminServer) FindDefaultGroup(ctx context.Context, req *admin.FindDefau
}

func (o *adminServer) SearchDefaultGroup(ctx context.Context, req *admin.SearchDefaultGroupReq) (*admin.SearchDefaultGroupResp, error) {
defer log.ZInfo(ctx, "return")
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions internal/rpc/admin/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ package admin

import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"

"github.com/OpenIMSDK/chat/pkg/common/config"
"github.com/OpenIMSDK/chat/pkg/common/tokenverify"
"github.com/OpenIMSDK/chat/pkg/proto/admin"
)

func (*adminServer) CreateToken(ctx context.Context, req *admin.CreateTokenReq) (*admin.CreateTokenResp, error) {
defer log.ZDebug(ctx, "return")
token, err := tokenverify.CreateToken(req.UserID, req.UserType, *config.Config.TokenPolicy.Expire)
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions internal/rpc/admin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
)

func (o *adminServer) CancellationUser(ctx context.Context, req *admin.CancellationUserReq) (*admin.CancellationUserResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand All @@ -49,6 +50,7 @@ func (o *adminServer) CancellationUser(ctx context.Context, req *admin.Cancellat
}

func (o *adminServer) BlockUser(ctx context.Context, req *admin.BlockUserReq) (*admin.BlockUserResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand All @@ -74,6 +76,7 @@ func (o *adminServer) BlockUser(ctx context.Context, req *admin.BlockUserReq) (*
}

func (o *adminServer) UnblockUser(ctx context.Context, req *admin.UnblockUserReq) (*admin.UnblockUserResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand All @@ -98,6 +101,7 @@ func (o *adminServer) UnblockUser(ctx context.Context, req *admin.UnblockUserReq
}

func (o *adminServer) SearchBlockUser(ctx context.Context, req *admin.SearchBlockUserReq) (*admin.SearchBlockUserResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down Expand Up @@ -134,6 +138,7 @@ func (o *adminServer) SearchBlockUser(ctx context.Context, req *admin.SearchBloc
}

func (o *adminServer) FindUserBlockInfo(ctx context.Context, req *admin.FindUserBlockInfoReq) (*admin.FindUserBlockInfoResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions internal/rpc/admin/user_ip_limit_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package admin

import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"time"

"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
Expand All @@ -27,6 +28,7 @@ import (
)

func (o *adminServer) SearchUserIPLimitLogin(ctx context.Context, req *admin.SearchUserIPLimitLoginReq) (*admin.SearchUserIPLimitLoginResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand All @@ -52,6 +54,7 @@ func (o *adminServer) SearchUserIPLimitLogin(ctx context.Context, req *admin.Sea
}

func (o *adminServer) AddUserIPLimitLogin(ctx context.Context, req *admin.AddUserIPLimitLoginReq) (*admin.AddUserIPLimitLoginResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := mctx.CheckAdmin(ctx); err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions internal/rpc/chat/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
)

func (o *chatSvr) OpenIMCallback(ctx context.Context, req *chat.OpenIMCallbackReq) (*chat.OpenIMCallbackResp, error) {
defer log.ZDebug(ctx, "return")
switch req.Command {
case constant.CallbackBeforeAddFriendCommand:
var data callbackstruct.CallbackBeforeAddFriendReq
Expand Down
5 changes: 5 additions & 0 deletions internal/rpc/chat/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (o *chatSvr) verifyCodeJoin(areaCode, phoneNumber string) string {
}

func (o *chatSvr) SendVerifyCode(ctx context.Context, req *chat.SendVerifyCodeReq) (*chat.SendVerifyCodeResp, error) {
defer log.ZDebug(ctx, "return")
switch req.UsedFor {
case constant.VerificationCodeForRegister:
if err := o.Admin.CheckRegister(ctx, req.Ip); err != nil {
Expand Down Expand Up @@ -120,6 +121,7 @@ func (o *chatSvr) SendVerifyCode(ctx context.Context, req *chat.SendVerifyCodeRe
}

func (o *chatSvr) verifyCode(ctx context.Context, account string, verifyCode string) (uint, error) {
defer log.ZDebug(ctx, "return")
if verifyCode == "" {
return 0, errs.ErrArgs.Wrap("verify code is empty")
}
Expand Down Expand Up @@ -159,6 +161,7 @@ func (o *chatSvr) verifyCode(ctx context.Context, account string, verifyCode str
}

func (o *chatSvr) VerifyCode(ctx context.Context, req *chat.VerifyCodeReq) (*chat.VerifyCodeResp, error) {
defer log.ZDebug(ctx, "return")
if _, err := o.verifyCode(ctx, o.verifyCodeJoin(req.AreaCode, req.PhoneNumber), req.VerifyCode); err != nil {
return nil, err
}
Expand Down Expand Up @@ -191,6 +194,7 @@ func (o *chatSvr) genVerifyCode() string {
}

func (o *chatSvr) RegisterUser(ctx context.Context, req *chat.RegisterUserReq) (*chat.RegisterUserResp, error) {
defer log.ZDebug(ctx, "return")
isAdmin, err := o.Admin.CheckNilOrAdmin(ctx)
if err != nil {
return nil, err
Expand Down Expand Up @@ -363,6 +367,7 @@ func (o *chatSvr) RegisterUser(ctx context.Context, req *chat.RegisterUserReq) (
}

func (o *chatSvr) Login(ctx context.Context, req *chat.LoginReq) (*chat.LoginResp, error) {
defer log.ZDebug(ctx, "return")
resp := &chat.LoginResp{}
if req.Password == "" && req.VerifyCode == "" {
return nil, errs.ErrArgs.Wrap("password or code must be set")
Expand Down
Loading

0 comments on commit dd5e1d0

Please sign in to comment.