From 846a1615d2783ae5b264e76c83928c8b11bb9cbe Mon Sep 17 00:00:00 2001 From: Michael Li Date: Fri, 9 Feb 2024 21:29:03 +0800 Subject: [PATCH] upgrade github.com/alimy/mir/v4 => v4.2.0.alpha.1 --- auto/api/m/v1/user.go | 15 +-- auto/api/r/v1/user.go | 15 +-- auto/api/s/v1/user.go | 21 ++-- auto/api/v1/admin.go | 15 +-- auto/api/v1/alipay_priv.go | 21 ++-- auto/api/v1/alipay_pub.go | 9 +- auto/api/v1/core.go | 99 +++++++++---------- auto/api/v1/followship.go | 27 ++--- auto/api/v1/friendship.go | 33 ++++--- auto/api/v1/loose.go | 39 ++++---- auto/api/v1/priv.go | 147 ++++++++++++++-------------- auto/api/v1/pub.go | 33 ++++--- auto/api/v1/relax.go | 9 +- auto/api/v1/site.go | 15 +-- auto/api/v1/trends.go | 9 +- auto/api/x/v1/user.go | 15 +-- go.mod | 2 +- go.sum | 4 +- internal/conf/telemetry.go | 2 +- internal/model/joint/trace.go | 24 ----- internal/model/web/admin.go | 9 +- internal/model/web/core.go | 3 +- internal/model/web/friendship.go | 23 ++--- internal/model/web/loose.go | 27 +++-- internal/model/web/priv.go | 22 ++--- internal/servants/base/base.go | 52 +++------- internal/servants/web/admin.go | 7 +- internal/servants/web/alipay.go | 9 +- internal/servants/web/core.go | 40 ++++---- internal/servants/web/followship.go | 10 +- internal/servants/web/friendship.go | 20 ++-- internal/servants/web/loose.go | 73 +++++++------- internal/servants/web/priv.go | 58 +++++------ internal/servants/web/pub.go | 10 +- internal/servants/web/relax.go | 4 +- internal/servants/web/site.go | 6 +- internal/servants/web/trends.go | 3 +- mirc/gen.go | 1 + 38 files changed, 447 insertions(+), 484 deletions(-) delete mode 100644 internal/model/joint/trace.go diff --git a/auto/api/m/v1/user.go b/auto/api/m/v1/user.go index 45d7fbba3..25de2e11a 100644 --- a/auto/api/m/v1/user.go +++ b/auto/api/m/v1/user.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -55,8 +56,8 @@ type User interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain - Logout() mir.Error - Login(*LoginReq) (*LoginResp, mir.Error) + Logout(context.Context) mir.Error + Login(context.Context, *LoginReq) (*LoginResp, mir.Error) mustEmbedUnimplementedUserServant() } @@ -76,7 +77,7 @@ func RegisterUserServant(e *gin.Engine, s User) { default: } - s.Render(c, nil, s.Logout()) + s.Render(c, nil, s.Logout(c.Request.Context())) }) router.Handle("POST", "/user/login/", func(c *gin.Context) { select { @@ -89,7 +90,7 @@ func RegisterUserServant(e *gin.Engine, s User) { s.Render(c, nil, err) return } - resp, err := s.Login(req) + resp, err := s.Login(c.Request.Context(), req) s.Render(c, resp, err) }) } @@ -101,11 +102,11 @@ func (UnimplementedUserServant) Chain() gin.HandlersChain { return nil } -func (UnimplementedUserServant) Logout() mir.Error { +func (UnimplementedUserServant) Logout(c context.Context) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedUserServant) Login(req *LoginReq) (*LoginResp, mir.Error) { +func (UnimplementedUserServant) Login(c context.Context, req *LoginReq) (*LoginResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/r/v1/user.go b/auto/api/r/v1/user.go index 8c385f149..e3c611a74 100644 --- a/auto/api/r/v1/user.go +++ b/auto/api/r/v1/user.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -55,8 +56,8 @@ type User interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain - Logout() mir.Error - Login(*LoginReq) (*LoginResp, mir.Error) + Logout(context.Context) mir.Error + Login(context.Context, *LoginReq) (*LoginResp, mir.Error) mustEmbedUnimplementedUserServant() } @@ -76,7 +77,7 @@ func RegisterUserServant(e *gin.Engine, s User) { default: } - s.Render(c, nil, s.Logout()) + s.Render(c, nil, s.Logout(c.Request.Context())) }) router.Handle("POST", "/user/login/", func(c *gin.Context) { select { @@ -89,7 +90,7 @@ func RegisterUserServant(e *gin.Engine, s User) { s.Render(c, nil, err) return } - resp, err := s.Login(req) + resp, err := s.Login(c.Request.Context(), req) s.Render(c, resp, err) }) } @@ -101,11 +102,11 @@ func (UnimplementedUserServant) Chain() gin.HandlersChain { return nil } -func (UnimplementedUserServant) Logout() mir.Error { +func (UnimplementedUserServant) Logout(c context.Context) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedUserServant) Login(req *LoginReq) (*LoginResp, mir.Error) { +func (UnimplementedUserServant) Login(c context.Context, req *LoginReq) (*LoginResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/s/v1/user.go b/auto/api/s/v1/user.go index a876f6b76..f8c61d71c 100644 --- a/auto/api/s/v1/user.go +++ b/auto/api/s/v1/user.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -52,9 +53,9 @@ type UserInfo struct { type User interface { _default_ - Logout() mir.Error - Login(*LoginReq) (*LoginResp, mir.Error) - Index() mir.Error + Logout(context.Context) mir.Error + Login(context.Context, *LoginReq) (*LoginResp, mir.Error) + Index(context.Context) mir.Error mustEmbedUnimplementedUserServant() } @@ -71,7 +72,7 @@ func RegisterUserServant(e *gin.Engine, s User) { default: } - s.Render(c, nil, s.Logout()) + s.Render(c, nil, s.Logout(c.Request.Context())) }) router.Handle("POST", "/user/login/", func(c *gin.Context) { select { @@ -84,7 +85,7 @@ func RegisterUserServant(e *gin.Engine, s User) { s.Render(c, nil, err) return } - resp, err := s.Login(req) + resp, err := s.Login(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/index/", func(c *gin.Context) { @@ -94,22 +95,22 @@ func RegisterUserServant(e *gin.Engine, s User) { default: } - s.Render(c, nil, s.Index()) + s.Render(c, nil, s.Index(c.Request.Context())) }) } // UnimplementedUserServant can be embedded to have forward compatible implementations. type UnimplementedUserServant struct{} -func (UnimplementedUserServant) Logout() mir.Error { +func (UnimplementedUserServant) Logout(c context.Context) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedUserServant) Login(req *LoginReq) (*LoginResp, mir.Error) { +func (UnimplementedUserServant) Login(c context.Context, req *LoginReq) (*LoginResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedUserServant) Index() mir.Error { +func (UnimplementedUserServant) Index(c context.Context) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/v1/admin.go b/auto/api/v1/admin.go index 4c3af4484..bcbd16e31 100644 --- a/auto/api/v1/admin.go +++ b/auto/api/v1/admin.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -31,8 +32,8 @@ type Admin interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain - SiteInfo(*web.SiteInfoReq) (*web.SiteInfoResp, mir.Error) - ChangeUserStatus(*web.ChangeUserStatusReq) mir.Error + SiteInfo(context.Context, *web.SiteInfoReq) (*web.SiteInfoResp, mir.Error) + ChangeUserStatus(context.Context, *web.ChangeUserStatusReq) mir.Error mustEmbedUnimplementedAdminServant() } @@ -56,7 +57,7 @@ func RegisterAdminServant(e *gin.Engine, s Admin) { s.Render(c, nil, err) return } - resp, err := s.SiteInfo(req) + resp, err := s.SiteInfo(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/admin/user/status", func(c *gin.Context) { @@ -70,7 +71,7 @@ func RegisterAdminServant(e *gin.Engine, s Admin) { s.Render(c, nil, err) return } - s.Render(c, nil, s.ChangeUserStatus(req)) + s.Render(c, nil, s.ChangeUserStatus(c.Request.Context(), req)) }) } @@ -81,11 +82,11 @@ func (UnimplementedAdminServant) Chain() gin.HandlersChain { return nil } -func (UnimplementedAdminServant) SiteInfo(req *web.SiteInfoReq) (*web.SiteInfoResp, mir.Error) { +func (UnimplementedAdminServant) SiteInfo(c context.Context, req *web.SiteInfoReq) (*web.SiteInfoResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedAdminServant) ChangeUserStatus(req *web.ChangeUserStatusReq) mir.Error { +func (UnimplementedAdminServant) ChangeUserStatus(c context.Context, req *web.ChangeUserStatusReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/v1/alipay_priv.go b/auto/api/v1/alipay_priv.go index 3c3ee1f50..c5458366f 100644 --- a/auto/api/v1/alipay_priv.go +++ b/auto/api/v1/alipay_priv.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -18,9 +19,9 @@ type AlipayPriv interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain - UserWalletBills(*web.UserWalletBillsReq) (*web.UserWalletBillsResp, mir.Error) - UserRechargeResult(*web.UserRechargeResultReq) (*web.UserRechargeResultResp, mir.Error) - UserRechargeLink(*web.UserRechargeLinkReq) (*web.UserRechargeLinkResp, mir.Error) + UserWalletBills(context.Context, *web.UserWalletBillsReq) (*web.UserWalletBillsResp, mir.Error) + UserRechargeResult(context.Context, *web.UserRechargeResultReq) (*web.UserRechargeResultResp, mir.Error) + UserRechargeLink(context.Context, *web.UserRechargeLinkReq) (*web.UserRechargeLinkResp, mir.Error) mustEmbedUnimplementedAlipayPrivServant() } @@ -45,7 +46,7 @@ func RegisterAlipayPrivServant(e *gin.Engine, s AlipayPriv) { s.Render(c, nil, err) return } - resp, err := s.UserWalletBills(req) + resp, err := s.UserWalletBills(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/user/recharge", func(c *gin.Context) { @@ -60,7 +61,7 @@ func RegisterAlipayPrivServant(e *gin.Engine, s AlipayPriv) { s.Render(c, nil, err) return } - resp, err := s.UserRechargeResult(req) + resp, err := s.UserRechargeResult(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/user/recharge", func(c *gin.Context) { @@ -75,7 +76,7 @@ func RegisterAlipayPrivServant(e *gin.Engine, s AlipayPriv) { s.Render(c, nil, err) return } - resp, err := s.UserRechargeLink(req) + resp, err := s.UserRechargeLink(c.Request.Context(), req) s.Render(c, resp, err) }) } @@ -87,15 +88,15 @@ func (UnimplementedAlipayPrivServant) Chain() gin.HandlersChain { return nil } -func (UnimplementedAlipayPrivServant) UserWalletBills(req *web.UserWalletBillsReq) (*web.UserWalletBillsResp, mir.Error) { +func (UnimplementedAlipayPrivServant) UserWalletBills(c context.Context, req *web.UserWalletBillsReq) (*web.UserWalletBillsResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedAlipayPrivServant) UserRechargeResult(req *web.UserRechargeResultReq) (*web.UserRechargeResultResp, mir.Error) { +func (UnimplementedAlipayPrivServant) UserRechargeResult(c context.Context, req *web.UserRechargeResultReq) (*web.UserRechargeResultResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedAlipayPrivServant) UserRechargeLink(req *web.UserRechargeLinkReq) (*web.UserRechargeLinkResp, mir.Error) { +func (UnimplementedAlipayPrivServant) UserRechargeLink(c context.Context, req *web.UserRechargeLinkReq) (*web.UserRechargeLinkResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/v1/alipay_pub.go b/auto/api/v1/alipay_pub.go index e1c3e8b79..699e638be 100644 --- a/auto/api/v1/alipay_pub.go +++ b/auto/api/v1/alipay_pub.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -15,7 +16,7 @@ import ( type AlipayPub interface { _default_ - AlipayNotify(*web.AlipayNotifyReq) mir.Error + AlipayNotify(context.Context, *web.AlipayNotifyReq) mir.Error mustEmbedUnimplementedAlipayPubServant() } @@ -37,14 +38,14 @@ func RegisterAlipayPubServant(e *gin.Engine, s AlipayPub) { s.Render(c, nil, err) return } - s.Render(c, nil, s.AlipayNotify(req)) + s.Render(c, nil, s.AlipayNotify(c.Request.Context(), req)) }) } // UnimplementedAlipayPubServant can be embedded to have forward compatible implementations. type UnimplementedAlipayPubServant struct{} -func (UnimplementedAlipayPubServant) AlipayNotify(req *web.AlipayNotifyReq) mir.Error { +func (UnimplementedAlipayPubServant) AlipayNotify(c context.Context, req *web.AlipayNotifyReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/v1/core.go b/auto/api/v1/core.go index 911445ab0..c106ad8ea 100644 --- a/auto/api/v1/core.go +++ b/auto/api/v1/core.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -18,22 +19,22 @@ type Core interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain - TweetCollectionStatus(*web.TweetCollectionStatusReq) (*web.TweetCollectionStatusResp, mir.Error) - TweetStarStatus(*web.TweetStarStatusReq) (*web.TweetStarStatusResp, mir.Error) - SuggestTags(*web.SuggestTagsReq) (*web.SuggestTagsResp, mir.Error) - SuggestUsers(*web.SuggestUsersReq) (*web.SuggestUsersResp, mir.Error) - ChangeAvatar(*web.ChangeAvatarReq) mir.Error - ChangeNickname(*web.ChangeNicknameReq) mir.Error - ChangePassword(*web.ChangePasswordReq) mir.Error - UserPhoneBind(*web.UserPhoneBindReq) mir.Error - GetStars(*web.GetStarsReq) (*web.GetStarsResp, mir.Error) - GetCollections(*web.GetCollectionsReq) (*web.GetCollectionsResp, mir.Error) - SendUserWhisper(*web.SendWhisperReq) mir.Error - ReadAllMessage(*web.ReadAllMessageReq) mir.Error - ReadMessage(*web.ReadMessageReq) mir.Error - GetMessages(*web.GetMessagesReq) (*web.GetMessagesResp, mir.Error) - GetUserInfo(*web.UserInfoReq) (*web.UserInfoResp, mir.Error) - SyncSearchIndex(*web.SyncSearchIndexReq) mir.Error + TweetCollectionStatus(context.Context, *web.TweetCollectionStatusReq) (*web.TweetCollectionStatusResp, mir.Error) + TweetStarStatus(context.Context, *web.TweetStarStatusReq) (*web.TweetStarStatusResp, mir.Error) + SuggestTags(context.Context, *web.SuggestTagsReq) (*web.SuggestTagsResp, mir.Error) + SuggestUsers(context.Context, *web.SuggestUsersReq) (*web.SuggestUsersResp, mir.Error) + ChangeAvatar(context.Context, *web.ChangeAvatarReq) mir.Error + ChangeNickname(context.Context, *web.ChangeNicknameReq) mir.Error + ChangePassword(context.Context, *web.ChangePasswordReq) mir.Error + UserPhoneBind(context.Context, *web.UserPhoneBindReq) mir.Error + GetStars(context.Context, *web.GetStarsReq) (*web.GetStarsResp, mir.Error) + GetCollections(context.Context, *web.GetCollectionsReq) (*web.GetCollectionsResp, mir.Error) + SendUserWhisper(context.Context, *web.SendWhisperReq) mir.Error + ReadAllMessage(context.Context, *web.ReadAllMessageReq) mir.Error + ReadMessage(context.Context, *web.ReadMessageReq) mir.Error + GetMessages(context.Context, *web.GetMessagesReq) (*web.GetMessagesResp, mir.Error) + GetUserInfo(context.Context, *web.UserInfoReq) (*web.UserInfoResp, mir.Error) + SyncSearchIndex(context.Context, *web.SyncSearchIndexReq) mir.Error mustEmbedUnimplementedCoreServant() } @@ -58,7 +59,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - resp, err := s.TweetCollectionStatus(req) + resp, err := s.TweetCollectionStatus(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/post/star", func(c *gin.Context) { @@ -73,7 +74,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - resp, err := s.TweetStarStatus(req) + resp, err := s.TweetStarStatus(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/suggest/tags", func(c *gin.Context) { @@ -88,7 +89,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - resp, err := s.SuggestTags(req) + resp, err := s.SuggestTags(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/suggest/users", func(c *gin.Context) { @@ -103,7 +104,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - resp, err := s.SuggestUsers(req) + resp, err := s.SuggestUsers(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/user/avatar", func(c *gin.Context) { @@ -117,7 +118,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - s.Render(c, nil, s.ChangeAvatar(req)) + s.Render(c, nil, s.ChangeAvatar(c.Request.Context(), req)) }) router.Handle("POST", "/user/nickname", func(c *gin.Context) { select { @@ -130,7 +131,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - s.Render(c, nil, s.ChangeNickname(req)) + s.Render(c, nil, s.ChangeNickname(c.Request.Context(), req)) }) router.Handle("POST", "/user/password", func(c *gin.Context) { select { @@ -143,7 +144,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - s.Render(c, nil, s.ChangePassword(req)) + s.Render(c, nil, s.ChangePassword(c.Request.Context(), req)) }) router.Handle("POST", "/user/phone", func(c *gin.Context) { select { @@ -156,7 +157,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - s.Render(c, nil, s.UserPhoneBind(req)) + s.Render(c, nil, s.UserPhoneBind(c.Request.Context(), req)) }) router.Handle("GET", "/user/stars", func(c *gin.Context) { select { @@ -170,7 +171,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - resp, err := s.GetStars(req) + resp, err := s.GetStars(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/user/collections", func(c *gin.Context) { @@ -185,7 +186,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - resp, err := s.GetCollections(req) + resp, err := s.GetCollections(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/user/whisper", func(c *gin.Context) { @@ -199,7 +200,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - s.Render(c, nil, s.SendUserWhisper(req)) + s.Render(c, nil, s.SendUserWhisper(c.Request.Context(), req)) }) router.Handle("POST", "/user/message/readall", func(c *gin.Context) { select { @@ -212,7 +213,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - s.Render(c, nil, s.ReadAllMessage(req)) + s.Render(c, nil, s.ReadAllMessage(c.Request.Context(), req)) }) router.Handle("POST", "/user/message/read", func(c *gin.Context) { select { @@ -225,7 +226,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - s.Render(c, nil, s.ReadMessage(req)) + s.Render(c, nil, s.ReadMessage(c.Request.Context(), req)) }) router.Handle("GET", "/user/messages", func(c *gin.Context) { select { @@ -238,7 +239,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - resp, err := s.GetMessages(req) + resp, err := s.GetMessages(c.Request.Context(), req) if err != nil { s.Render(c, nil, err) return @@ -258,7 +259,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - resp, err := s.GetUserInfo(req) + resp, err := s.GetUserInfo(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/sync/index", func(c *gin.Context) { @@ -272,7 +273,7 @@ func RegisterCoreServant(e *gin.Engine, s Core) { s.Render(c, nil, err) return } - s.Render(c, nil, s.SyncSearchIndex(req)) + s.Render(c, nil, s.SyncSearchIndex(c.Request.Context(), req)) }) } @@ -283,67 +284,67 @@ func (UnimplementedCoreServant) Chain() gin.HandlersChain { return nil } -func (UnimplementedCoreServant) TweetCollectionStatus(req *web.TweetCollectionStatusReq) (*web.TweetCollectionStatusResp, mir.Error) { +func (UnimplementedCoreServant) TweetCollectionStatus(c context.Context, req *web.TweetCollectionStatusReq) (*web.TweetCollectionStatusResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) TweetStarStatus(req *web.TweetStarStatusReq) (*web.TweetStarStatusResp, mir.Error) { +func (UnimplementedCoreServant) TweetStarStatus(c context.Context, req *web.TweetStarStatusReq) (*web.TweetStarStatusResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) SuggestTags(req *web.SuggestTagsReq) (*web.SuggestTagsResp, mir.Error) { +func (UnimplementedCoreServant) SuggestTags(c context.Context, req *web.SuggestTagsReq) (*web.SuggestTagsResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) SuggestUsers(req *web.SuggestUsersReq) (*web.SuggestUsersResp, mir.Error) { +func (UnimplementedCoreServant) SuggestUsers(c context.Context, req *web.SuggestUsersReq) (*web.SuggestUsersResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) ChangeAvatar(req *web.ChangeAvatarReq) mir.Error { +func (UnimplementedCoreServant) ChangeAvatar(c context.Context, req *web.ChangeAvatarReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) ChangeNickname(req *web.ChangeNicknameReq) mir.Error { +func (UnimplementedCoreServant) ChangeNickname(c context.Context, req *web.ChangeNicknameReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) ChangePassword(req *web.ChangePasswordReq) mir.Error { +func (UnimplementedCoreServant) ChangePassword(c context.Context, req *web.ChangePasswordReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) UserPhoneBind(req *web.UserPhoneBindReq) mir.Error { +func (UnimplementedCoreServant) UserPhoneBind(c context.Context, req *web.UserPhoneBindReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) GetStars(req *web.GetStarsReq) (*web.GetStarsResp, mir.Error) { +func (UnimplementedCoreServant) GetStars(c context.Context, req *web.GetStarsReq) (*web.GetStarsResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) GetCollections(req *web.GetCollectionsReq) (*web.GetCollectionsResp, mir.Error) { +func (UnimplementedCoreServant) GetCollections(c context.Context, req *web.GetCollectionsReq) (*web.GetCollectionsResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) SendUserWhisper(req *web.SendWhisperReq) mir.Error { +func (UnimplementedCoreServant) SendUserWhisper(c context.Context, req *web.SendWhisperReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) ReadAllMessage(req *web.ReadAllMessageReq) mir.Error { +func (UnimplementedCoreServant) ReadAllMessage(c context.Context, req *web.ReadAllMessageReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) ReadMessage(req *web.ReadMessageReq) mir.Error { +func (UnimplementedCoreServant) ReadMessage(c context.Context, req *web.ReadMessageReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) GetMessages(req *web.GetMessagesReq) (*web.GetMessagesResp, mir.Error) { +func (UnimplementedCoreServant) GetMessages(c context.Context, req *web.GetMessagesReq) (*web.GetMessagesResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) GetUserInfo(req *web.UserInfoReq) (*web.UserInfoResp, mir.Error) { +func (UnimplementedCoreServant) GetUserInfo(c context.Context, req *web.UserInfoReq) (*web.UserInfoResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedCoreServant) SyncSearchIndex(req *web.SyncSearchIndexReq) mir.Error { +func (UnimplementedCoreServant) SyncSearchIndex(c context.Context, req *web.SyncSearchIndexReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/v1/followship.go b/auto/api/v1/followship.go index c0041feb0..8158d8b1a 100644 --- a/auto/api/v1/followship.go +++ b/auto/api/v1/followship.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -18,10 +19,10 @@ type Followship interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain - ListFollowings(*web.ListFollowingsReq) (*web.ListFollowingsResp, mir.Error) - ListFollows(*web.ListFollowsReq) (*web.ListFollowsResp, mir.Error) - UnfollowUser(*web.UnfollowUserReq) mir.Error - FollowUser(*web.FollowUserReq) mir.Error + ListFollowings(context.Context, *web.ListFollowingsReq) (*web.ListFollowingsResp, mir.Error) + ListFollows(context.Context, *web.ListFollowsReq) (*web.ListFollowsResp, mir.Error) + UnfollowUser(context.Context, *web.UnfollowUserReq) mir.Error + FollowUser(context.Context, *web.FollowUserReq) mir.Error mustEmbedUnimplementedFollowshipServant() } @@ -45,7 +46,7 @@ func RegisterFollowshipServant(e *gin.Engine, s Followship) { s.Render(c, nil, err) return } - resp, err := s.ListFollowings(req) + resp, err := s.ListFollowings(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/user/follows", func(c *gin.Context) { @@ -59,7 +60,7 @@ func RegisterFollowshipServant(e *gin.Engine, s Followship) { s.Render(c, nil, err) return } - resp, err := s.ListFollows(req) + resp, err := s.ListFollows(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/user/unfollow", func(c *gin.Context) { @@ -73,7 +74,7 @@ func RegisterFollowshipServant(e *gin.Engine, s Followship) { s.Render(c, nil, err) return } - s.Render(c, nil, s.UnfollowUser(req)) + s.Render(c, nil, s.UnfollowUser(c.Request.Context(), req)) }) router.Handle("POST", "/user/follow", func(c *gin.Context) { select { @@ -86,7 +87,7 @@ func RegisterFollowshipServant(e *gin.Engine, s Followship) { s.Render(c, nil, err) return } - s.Render(c, nil, s.FollowUser(req)) + s.Render(c, nil, s.FollowUser(c.Request.Context(), req)) }) } @@ -97,19 +98,19 @@ func (UnimplementedFollowshipServant) Chain() gin.HandlersChain { return nil } -func (UnimplementedFollowshipServant) ListFollowings(req *web.ListFollowingsReq) (*web.ListFollowingsResp, mir.Error) { +func (UnimplementedFollowshipServant) ListFollowings(c context.Context, req *web.ListFollowingsReq) (*web.ListFollowingsResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedFollowshipServant) ListFollows(req *web.ListFollowsReq) (*web.ListFollowsResp, mir.Error) { +func (UnimplementedFollowshipServant) ListFollows(c context.Context, req *web.ListFollowsReq) (*web.ListFollowsResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedFollowshipServant) UnfollowUser(req *web.UnfollowUserReq) mir.Error { +func (UnimplementedFollowshipServant) UnfollowUser(c context.Context, req *web.UnfollowUserReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedFollowshipServant) FollowUser(req *web.FollowUserReq) mir.Error { +func (UnimplementedFollowshipServant) FollowUser(c context.Context, req *web.FollowUserReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/v1/friendship.go b/auto/api/v1/friendship.go index 6165822bd..b5b42a9d2 100644 --- a/auto/api/v1/friendship.go +++ b/auto/api/v1/friendship.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -18,11 +19,11 @@ type Friendship interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain - GetContacts(*web.GetContactsReq) (*web.GetContactsResp, mir.Error) - DeleteFriend(*web.DeleteFriendReq) mir.Error - RejectFriend(*web.RejectFriendReq) mir.Error - AddFriend(*web.AddFriendReq) mir.Error - RequestingFriend(*web.RequestingFriendReq) mir.Error + GetContacts(context.Context, *web.GetContactsReq) (*web.GetContactsResp, mir.Error) + DeleteFriend(context.Context, *web.DeleteFriendReq) mir.Error + RejectFriend(context.Context, *web.RejectFriendReq) mir.Error + AddFriend(context.Context, *web.AddFriendReq) mir.Error + RequestingFriend(context.Context, *web.RequestingFriendReq) mir.Error mustEmbedUnimplementedFriendshipServant() } @@ -46,7 +47,7 @@ func RegisterFriendshipServant(e *gin.Engine, s Friendship) { s.Render(c, nil, err) return } - resp, err := s.GetContacts(req) + resp, err := s.GetContacts(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/friend/delete", func(c *gin.Context) { @@ -60,7 +61,7 @@ func RegisterFriendshipServant(e *gin.Engine, s Friendship) { s.Render(c, nil, err) return } - s.Render(c, nil, s.DeleteFriend(req)) + s.Render(c, nil, s.DeleteFriend(c.Request.Context(), req)) }) router.Handle("POST", "/friend/reject", func(c *gin.Context) { select { @@ -73,7 +74,7 @@ func RegisterFriendshipServant(e *gin.Engine, s Friendship) { s.Render(c, nil, err) return } - s.Render(c, nil, s.RejectFriend(req)) + s.Render(c, nil, s.RejectFriend(c.Request.Context(), req)) }) router.Handle("POST", "/friend/add", func(c *gin.Context) { select { @@ -86,7 +87,7 @@ func RegisterFriendshipServant(e *gin.Engine, s Friendship) { s.Render(c, nil, err) return } - s.Render(c, nil, s.AddFriend(req)) + s.Render(c, nil, s.AddFriend(c.Request.Context(), req)) }) router.Handle("POST", "/friend/requesting", func(c *gin.Context) { select { @@ -99,7 +100,7 @@ func RegisterFriendshipServant(e *gin.Engine, s Friendship) { s.Render(c, nil, err) return } - s.Render(c, nil, s.RequestingFriend(req)) + s.Render(c, nil, s.RequestingFriend(c.Request.Context(), req)) }) } @@ -110,23 +111,23 @@ func (UnimplementedFriendshipServant) Chain() gin.HandlersChain { return nil } -func (UnimplementedFriendshipServant) GetContacts(req *web.GetContactsReq) (*web.GetContactsResp, mir.Error) { +func (UnimplementedFriendshipServant) GetContacts(c context.Context, req *web.GetContactsReq) (*web.GetContactsResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedFriendshipServant) DeleteFriend(req *web.DeleteFriendReq) mir.Error { +func (UnimplementedFriendshipServant) DeleteFriend(c context.Context, req *web.DeleteFriendReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedFriendshipServant) RejectFriend(req *web.RejectFriendReq) mir.Error { +func (UnimplementedFriendshipServant) RejectFriend(c context.Context, req *web.RejectFriendReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedFriendshipServant) AddFriend(req *web.AddFriendReq) mir.Error { +func (UnimplementedFriendshipServant) AddFriend(c context.Context, req *web.AddFriendReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedFriendshipServant) RequestingFriend(req *web.RequestingFriendReq) mir.Error { +func (UnimplementedFriendshipServant) RequestingFriend(c context.Context, req *web.RequestingFriendReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/v1/loose.go b/auto/api/v1/loose.go index dbf598d21..bb4fa44c2 100644 --- a/auto/api/v1/loose.go +++ b/auto/api/v1/loose.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -18,12 +19,12 @@ type Loose interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain - TweetDetail(*web.TweetDetailReq) (*web.TweetDetailResp, mir.Error) - TweetComments(*web.TweetCommentsReq) (*web.TweetCommentsResp, mir.Error) - TopicList(*web.TopicListReq) (*web.TopicListResp, mir.Error) - GetUserProfile(*web.GetUserProfileReq) (*web.GetUserProfileResp, mir.Error) - GetUserTweets(*web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) - Timeline(*web.TimelineReq) (*web.TimelineResp, mir.Error) + TweetDetail(context.Context, *web.TweetDetailReq) (*web.TweetDetailResp, mir.Error) + TweetComments(context.Context, *web.TweetCommentsReq) (*web.TweetCommentsResp, mir.Error) + TopicList(context.Context, *web.TopicListReq) (*web.TopicListResp, mir.Error) + GetUserProfile(context.Context, *web.GetUserProfileReq) (*web.GetUserProfileResp, mir.Error) + GetUserTweets(context.Context, *web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) + Timeline(context.Context, *web.TimelineReq) (*web.TimelineResp, mir.Error) mustEmbedUnimplementedLooseServant() } @@ -47,7 +48,7 @@ func RegisterLooseServant(e *gin.Engine, s Loose) { s.Render(c, nil, err) return } - resp, err := s.TweetDetail(req) + resp, err := s.TweetDetail(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/post/comments", func(c *gin.Context) { @@ -61,7 +62,7 @@ func RegisterLooseServant(e *gin.Engine, s Loose) { s.Render(c, nil, err) return } - resp, err := s.TweetComments(req) + resp, err := s.TweetComments(c.Request.Context(), req) if err != nil { s.Render(c, nil, err) return @@ -80,7 +81,7 @@ func RegisterLooseServant(e *gin.Engine, s Loose) { s.Render(c, nil, err) return } - resp, err := s.TopicList(req) + resp, err := s.TopicList(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/user/profile", func(c *gin.Context) { @@ -94,7 +95,7 @@ func RegisterLooseServant(e *gin.Engine, s Loose) { s.Render(c, nil, err) return } - resp, err := s.GetUserProfile(req) + resp, err := s.GetUserProfile(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/user/posts", func(c *gin.Context) { @@ -108,7 +109,7 @@ func RegisterLooseServant(e *gin.Engine, s Loose) { s.Render(c, nil, err) return } - resp, err := s.GetUserTweets(req) + resp, err := s.GetUserTweets(c.Request.Context(), req) if err != nil { s.Render(c, nil, err) return @@ -128,7 +129,7 @@ func RegisterLooseServant(e *gin.Engine, s Loose) { s.Render(c, nil, err) return } - resp, err := s.Timeline(req) + resp, err := s.Timeline(c.Request.Context(), req) if err != nil { s.Render(c, nil, err) return @@ -145,27 +146,27 @@ func (UnimplementedLooseServant) Chain() gin.HandlersChain { return nil } -func (UnimplementedLooseServant) TweetDetail(req *web.TweetDetailReq) (*web.TweetDetailResp, mir.Error) { +func (UnimplementedLooseServant) TweetDetail(c context.Context, req *web.TweetDetailReq) (*web.TweetDetailResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedLooseServant) TweetComments(req *web.TweetCommentsReq) (*web.TweetCommentsResp, mir.Error) { +func (UnimplementedLooseServant) TweetComments(c context.Context, req *web.TweetCommentsReq) (*web.TweetCommentsResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedLooseServant) TopicList(req *web.TopicListReq) (*web.TopicListResp, mir.Error) { +func (UnimplementedLooseServant) TopicList(c context.Context, req *web.TopicListReq) (*web.TopicListResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedLooseServant) GetUserProfile(req *web.GetUserProfileReq) (*web.GetUserProfileResp, mir.Error) { +func (UnimplementedLooseServant) GetUserProfile(c context.Context, req *web.GetUserProfileReq) (*web.GetUserProfileResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedLooseServant) GetUserTweets(req *web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) { +func (UnimplementedLooseServant) GetUserTweets(c context.Context, req *web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedLooseServant) Timeline(req *web.TimelineReq) (*web.TimelineResp, mir.Error) { +func (UnimplementedLooseServant) Timeline(c context.Context, req *web.TimelineReq) (*web.TimelineResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/v1/priv.go b/auto/api/v1/priv.go index a8f46943e..daf5170a5 100644 --- a/auto/api/v1/priv.go +++ b/auto/api/v1/priv.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -18,30 +19,30 @@ type Priv interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain - UnfollowTopic(*web.UnfollowTopicReq) mir.Error - FollowTopic(*web.FollowTopicReq) mir.Error - PinTopic(*web.PinTopicReq) (*web.PinTopicResp, mir.Error) - StickTopic(*web.StickTopicReq) (*web.StickTopicResp, mir.Error) - ThumbsDownTweetReply(*web.TweetReplyThumbsReq) mir.Error - ThumbsUpTweetReply(*web.TweetReplyThumbsReq) mir.Error - ThumbsDownTweetComment(*web.TweetCommentThumbsReq) mir.Error - ThumbsUpTweetComment(*web.TweetCommentThumbsReq) mir.Error - DeleteCommentReply(*web.DeleteCommentReplyReq) mir.Error - CreateCommentReply(*web.CreateCommentReplyReq) (*web.CreateCommentReplyResp, mir.Error) - HighlightComment(*web.HighlightCommentReq) (*web.HighlightCommentResp, mir.Error) - DeleteComment(*web.DeleteCommentReq) mir.Error - CreateComment(*web.CreateCommentReq) (*web.CreateCommentResp, mir.Error) - VisibleTweet(*web.VisibleTweetReq) (*web.VisibleTweetResp, mir.Error) - HighlightTweet(*web.HighlightTweetReq) (*web.HighlightTweetResp, mir.Error) - StickTweet(*web.StickTweetReq) (*web.StickTweetResp, mir.Error) - LockTweet(*web.LockTweetReq) (*web.LockTweetResp, mir.Error) - CollectionTweet(*web.CollectionTweetReq) (*web.CollectionTweetResp, mir.Error) - StarTweet(*web.StarTweetReq) (*web.StarTweetResp, mir.Error) - DeleteTweet(*web.DeleteTweetReq) mir.Error - CreateTweet(*web.CreateTweetReq) (*web.CreateTweetResp, mir.Error) - DownloadAttachment(*web.DownloadAttachmentReq) (*web.DownloadAttachmentResp, mir.Error) - DownloadAttachmentPrecheck(*web.DownloadAttachmentPrecheckReq) (*web.DownloadAttachmentPrecheckResp, mir.Error) - UploadAttachment(*web.UploadAttachmentReq) (*web.UploadAttachmentResp, mir.Error) + UnfollowTopic(context.Context, *web.UnfollowTopicReq) mir.Error + FollowTopic(context.Context, *web.FollowTopicReq) mir.Error + PinTopic(context.Context, *web.PinTopicReq) (*web.PinTopicResp, mir.Error) + StickTopic(context.Context, *web.StickTopicReq) (*web.StickTopicResp, mir.Error) + ThumbsDownTweetReply(context.Context, *web.TweetReplyThumbsReq) mir.Error + ThumbsUpTweetReply(context.Context, *web.TweetReplyThumbsReq) mir.Error + ThumbsDownTweetComment(context.Context, *web.TweetCommentThumbsReq) mir.Error + ThumbsUpTweetComment(context.Context, *web.TweetCommentThumbsReq) mir.Error + DeleteCommentReply(context.Context, *web.DeleteCommentReplyReq) mir.Error + CreateCommentReply(context.Context, *web.CreateCommentReplyReq) (*web.CreateCommentReplyResp, mir.Error) + HighlightComment(context.Context, *web.HighlightCommentReq) (*web.HighlightCommentResp, mir.Error) + DeleteComment(context.Context, *web.DeleteCommentReq) mir.Error + CreateComment(context.Context, *web.CreateCommentReq) (*web.CreateCommentResp, mir.Error) + VisibleTweet(context.Context, *web.VisibleTweetReq) (*web.VisibleTweetResp, mir.Error) + HighlightTweet(context.Context, *web.HighlightTweetReq) (*web.HighlightTweetResp, mir.Error) + StickTweet(context.Context, *web.StickTweetReq) (*web.StickTweetResp, mir.Error) + LockTweet(context.Context, *web.LockTweetReq) (*web.LockTweetResp, mir.Error) + CollectionTweet(context.Context, *web.CollectionTweetReq) (*web.CollectionTweetResp, mir.Error) + StarTweet(context.Context, *web.StarTweetReq) (*web.StarTweetResp, mir.Error) + DeleteTweet(context.Context, *web.DeleteTweetReq) mir.Error + CreateTweet(context.Context, *web.CreateTweetReq) (*web.CreateTweetResp, mir.Error) + DownloadAttachment(context.Context, *web.DownloadAttachmentReq) (*web.DownloadAttachmentResp, mir.Error) + DownloadAttachmentPrecheck(context.Context, *web.DownloadAttachmentPrecheckReq) (*web.DownloadAttachmentPrecheckResp, mir.Error) + UploadAttachment(context.Context, *web.UploadAttachmentReq) (*web.UploadAttachmentResp, mir.Error) mustEmbedUnimplementedPrivServant() } @@ -77,7 +78,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - s.Render(c, nil, s.UnfollowTopic(req)) + s.Render(c, nil, s.UnfollowTopic(c.Request.Context(), req)) }) router.Handle("POST", "/topic/follow", func(c *gin.Context) { select { @@ -90,7 +91,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - s.Render(c, nil, s.FollowTopic(req)) + s.Render(c, nil, s.FollowTopic(c.Request.Context(), req)) }) router.Handle("POST", "/topic/pin", func(c *gin.Context) { select { @@ -103,7 +104,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.PinTopic(req) + resp, err := s.PinTopic(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/topic/stick", func(c *gin.Context) { @@ -117,7 +118,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.StickTopic(req) + resp, err := s.StickTopic(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/tweet/reply/thumbsdown", func(c *gin.Context) { @@ -131,7 +132,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - s.Render(c, nil, s.ThumbsDownTweetReply(req)) + s.Render(c, nil, s.ThumbsDownTweetReply(c.Request.Context(), req)) }) router.Handle("POST", "/tweet/reply/thumbsup", func(c *gin.Context) { select { @@ -144,7 +145,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - s.Render(c, nil, s.ThumbsUpTweetReply(req)) + s.Render(c, nil, s.ThumbsUpTweetReply(c.Request.Context(), req)) }) router.Handle("POST", "/tweet/comment/thumbsdown", func(c *gin.Context) { select { @@ -157,7 +158,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - s.Render(c, nil, s.ThumbsDownTweetComment(req)) + s.Render(c, nil, s.ThumbsDownTweetComment(c.Request.Context(), req)) }) router.Handle("POST", "/tweet/comment/thumbsup", func(c *gin.Context) { select { @@ -170,7 +171,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - s.Render(c, nil, s.ThumbsUpTweetComment(req)) + s.Render(c, nil, s.ThumbsUpTweetComment(c.Request.Context(), req)) }) router.Handle("DELETE", "/post/comment/reply", func(c *gin.Context) { select { @@ -183,7 +184,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - s.Render(c, nil, s.DeleteCommentReply(req)) + s.Render(c, nil, s.DeleteCommentReply(c.Request.Context(), req)) }) router.Handle("POST", "/post/comment/reply", func(c *gin.Context) { select { @@ -197,7 +198,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.CreateCommentReply(req) + resp, err := s.CreateCommentReply(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/post/comment/highlight", func(c *gin.Context) { @@ -211,7 +212,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.HighlightComment(req) + resp, err := s.HighlightComment(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("DELETE", "/post/comment", func(c *gin.Context) { @@ -225,7 +226,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - s.Render(c, nil, s.DeleteComment(req)) + s.Render(c, nil, s.DeleteComment(c.Request.Context(), req)) }) router.Handle("POST", "/post/comment", func(c *gin.Context) { select { @@ -239,7 +240,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.CreateComment(req) + resp, err := s.CreateComment(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/post/visibility", func(c *gin.Context) { @@ -253,7 +254,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.VisibleTweet(req) + resp, err := s.VisibleTweet(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/post/highlight", func(c *gin.Context) { @@ -267,7 +268,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.HighlightTweet(req) + resp, err := s.HighlightTweet(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/post/stick", func(c *gin.Context) { @@ -281,7 +282,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.StickTweet(req) + resp, err := s.StickTweet(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/post/lock", func(c *gin.Context) { @@ -295,7 +296,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.LockTweet(req) + resp, err := s.LockTweet(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/post/collection", func(c *gin.Context) { @@ -309,7 +310,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.CollectionTweet(req) + resp, err := s.CollectionTweet(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/post/star", func(c *gin.Context) { @@ -323,7 +324,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.StarTweet(req) + resp, err := s.StarTweet(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("DELETE", "/post", func(c *gin.Context) { @@ -337,7 +338,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - s.Render(c, nil, s.DeleteTweet(req)) + s.Render(c, nil, s.DeleteTweet(c.Request.Context(), req)) }) router.Handle("POST", "/post", append(cc.ChainCreateTweet(), func(c *gin.Context) { select { @@ -351,7 +352,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.CreateTweet(req) + resp, err := s.CreateTweet(c.Request.Context(), req) if err != nil { s.Render(c, nil, err) return @@ -371,7 +372,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.DownloadAttachment(req) + resp, err := s.DownloadAttachment(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/attachment/precheck", func(c *gin.Context) { @@ -386,7 +387,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.DownloadAttachmentPrecheck(req) + resp, err := s.DownloadAttachmentPrecheck(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/attachment", func(c *gin.Context) { @@ -401,7 +402,7 @@ func RegisterPrivServant(e *gin.Engine, s Priv, m ...PrivChain) { s.Render(c, nil, err) return } - resp, err := s.UploadAttachment(req) + resp, err := s.UploadAttachment(c.Request.Context(), req) s.Render(c, resp, err) }) } @@ -413,99 +414,99 @@ func (UnimplementedPrivServant) Chain() gin.HandlersChain { return nil } -func (UnimplementedPrivServant) UnfollowTopic(req *web.UnfollowTopicReq) mir.Error { +func (UnimplementedPrivServant) UnfollowTopic(c context.Context, req *web.UnfollowTopicReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) FollowTopic(req *web.FollowTopicReq) mir.Error { +func (UnimplementedPrivServant) FollowTopic(c context.Context, req *web.FollowTopicReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) PinTopic(req *web.PinTopicReq) (*web.PinTopicResp, mir.Error) { +func (UnimplementedPrivServant) PinTopic(c context.Context, req *web.PinTopicReq) (*web.PinTopicResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) StickTopic(req *web.StickTopicReq) (*web.StickTopicResp, mir.Error) { +func (UnimplementedPrivServant) StickTopic(c context.Context, req *web.StickTopicReq) (*web.StickTopicResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) ThumbsDownTweetReply(req *web.TweetReplyThumbsReq) mir.Error { +func (UnimplementedPrivServant) ThumbsDownTweetReply(c context.Context, req *web.TweetReplyThumbsReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) ThumbsUpTweetReply(req *web.TweetReplyThumbsReq) mir.Error { +func (UnimplementedPrivServant) ThumbsUpTweetReply(c context.Context, req *web.TweetReplyThumbsReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) ThumbsDownTweetComment(req *web.TweetCommentThumbsReq) mir.Error { +func (UnimplementedPrivServant) ThumbsDownTweetComment(c context.Context, req *web.TweetCommentThumbsReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) ThumbsUpTweetComment(req *web.TweetCommentThumbsReq) mir.Error { +func (UnimplementedPrivServant) ThumbsUpTweetComment(c context.Context, req *web.TweetCommentThumbsReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) DeleteCommentReply(req *web.DeleteCommentReplyReq) mir.Error { +func (UnimplementedPrivServant) DeleteCommentReply(c context.Context, req *web.DeleteCommentReplyReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.CreateCommentReplyResp, mir.Error) { +func (UnimplementedPrivServant) CreateCommentReply(c context.Context, req *web.CreateCommentReplyReq) (*web.CreateCommentReplyResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) HighlightComment(req *web.HighlightCommentReq) (*web.HighlightCommentResp, mir.Error) { +func (UnimplementedPrivServant) HighlightComment(c context.Context, req *web.HighlightCommentReq) (*web.HighlightCommentResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) DeleteComment(req *web.DeleteCommentReq) mir.Error { +func (UnimplementedPrivServant) DeleteComment(c context.Context, req *web.DeleteCommentReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) CreateComment(req *web.CreateCommentReq) (*web.CreateCommentResp, mir.Error) { +func (UnimplementedPrivServant) CreateComment(c context.Context, req *web.CreateCommentReq) (*web.CreateCommentResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) VisibleTweet(req *web.VisibleTweetReq) (*web.VisibleTweetResp, mir.Error) { +func (UnimplementedPrivServant) VisibleTweet(c context.Context, req *web.VisibleTweetReq) (*web.VisibleTweetResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) HighlightTweet(req *web.HighlightTweetReq) (*web.HighlightTweetResp, mir.Error) { +func (UnimplementedPrivServant) HighlightTweet(c context.Context, req *web.HighlightTweetReq) (*web.HighlightTweetResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) StickTweet(req *web.StickTweetReq) (*web.StickTweetResp, mir.Error) { +func (UnimplementedPrivServant) StickTweet(c context.Context, req *web.StickTweetReq) (*web.StickTweetResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) LockTweet(req *web.LockTweetReq) (*web.LockTweetResp, mir.Error) { +func (UnimplementedPrivServant) LockTweet(c context.Context, req *web.LockTweetReq) (*web.LockTweetResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) CollectionTweet(req *web.CollectionTweetReq) (*web.CollectionTweetResp, mir.Error) { +func (UnimplementedPrivServant) CollectionTweet(c context.Context, req *web.CollectionTweetReq) (*web.CollectionTweetResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) StarTweet(req *web.StarTweetReq) (*web.StarTweetResp, mir.Error) { +func (UnimplementedPrivServant) StarTweet(c context.Context, req *web.StarTweetReq) (*web.StarTweetResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) DeleteTweet(req *web.DeleteTweetReq) mir.Error { +func (UnimplementedPrivServant) DeleteTweet(c context.Context, req *web.DeleteTweetReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) CreateTweet(req *web.CreateTweetReq) (*web.CreateTweetResp, mir.Error) { +func (UnimplementedPrivServant) CreateTweet(c context.Context, req *web.CreateTweetReq) (*web.CreateTweetResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) DownloadAttachment(req *web.DownloadAttachmentReq) (*web.DownloadAttachmentResp, mir.Error) { +func (UnimplementedPrivServant) DownloadAttachment(c context.Context, req *web.DownloadAttachmentReq) (*web.DownloadAttachmentResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) DownloadAttachmentPrecheck(req *web.DownloadAttachmentPrecheckReq) (*web.DownloadAttachmentPrecheckResp, mir.Error) { +func (UnimplementedPrivServant) DownloadAttachmentPrecheck(c context.Context, req *web.DownloadAttachmentPrecheckReq) (*web.DownloadAttachmentPrecheckResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPrivServant) UploadAttachment(req *web.UploadAttachmentReq) (*web.UploadAttachmentResp, mir.Error) { +func (UnimplementedPrivServant) UploadAttachment(c context.Context, req *web.UploadAttachmentReq) (*web.UploadAttachmentResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/v1/pub.go b/auto/api/v1/pub.go index 98a41440b..25bb4a8db 100644 --- a/auto/api/v1/pub.go +++ b/auto/api/v1/pub.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -15,11 +16,11 @@ import ( type Pub interface { _default_ - SendCaptcha(*web.SendCaptchaReq) mir.Error - GetCaptcha() (*web.GetCaptchaResp, mir.Error) - Register(*web.RegisterReq) (*web.RegisterResp, mir.Error) - Login(*web.LoginReq) (*web.LoginResp, mir.Error) - Version() (*web.VersionResp, mir.Error) + SendCaptcha(context.Context, *web.SendCaptchaReq) mir.Error + GetCaptcha(context.Context) (*web.GetCaptchaResp, mir.Error) + Register(context.Context, *web.RegisterReq) (*web.RegisterResp, mir.Error) + Login(context.Context, *web.LoginReq) (*web.LoginResp, mir.Error) + Version(context.Context) (*web.VersionResp, mir.Error) mustEmbedUnimplementedPubServant() } @@ -40,7 +41,7 @@ func RegisterPubServant(e *gin.Engine, s Pub) { s.Render(c, nil, err) return } - s.Render(c, nil, s.SendCaptcha(req)) + s.Render(c, nil, s.SendCaptcha(c.Request.Context(), req)) }) router.Handle("GET", "/captcha", func(c *gin.Context) { select { @@ -49,7 +50,7 @@ func RegisterPubServant(e *gin.Engine, s Pub) { default: } - resp, err := s.GetCaptcha() + resp, err := s.GetCaptcha(c.Request.Context()) s.Render(c, resp, err) }) router.Handle("POST", "/auth/register", func(c *gin.Context) { @@ -63,7 +64,7 @@ func RegisterPubServant(e *gin.Engine, s Pub) { s.Render(c, nil, err) return } - resp, err := s.Register(req) + resp, err := s.Register(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("POST", "/auth/login", func(c *gin.Context) { @@ -77,7 +78,7 @@ func RegisterPubServant(e *gin.Engine, s Pub) { s.Render(c, nil, err) return } - resp, err := s.Login(req) + resp, err := s.Login(c.Request.Context(), req) s.Render(c, resp, err) }) router.Handle("GET", "/", func(c *gin.Context) { @@ -87,7 +88,7 @@ func RegisterPubServant(e *gin.Engine, s Pub) { default: } - resp, err := s.Version() + resp, err := s.Version(c.Request.Context()) s.Render(c, resp, err) }) } @@ -95,23 +96,23 @@ func RegisterPubServant(e *gin.Engine, s Pub) { // UnimplementedPubServant can be embedded to have forward compatible implementations. type UnimplementedPubServant struct{} -func (UnimplementedPubServant) SendCaptcha(req *web.SendCaptchaReq) mir.Error { +func (UnimplementedPubServant) SendCaptcha(c context.Context, req *web.SendCaptchaReq) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPubServant) GetCaptcha() (*web.GetCaptchaResp, mir.Error) { +func (UnimplementedPubServant) GetCaptcha(c context.Context) (*web.GetCaptchaResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPubServant) Register(req *web.RegisterReq) (*web.RegisterResp, mir.Error) { +func (UnimplementedPubServant) Register(c context.Context, req *web.RegisterReq) (*web.RegisterResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPubServant) Login(req *web.LoginReq) (*web.LoginResp, mir.Error) { +func (UnimplementedPubServant) Login(c context.Context, req *web.LoginReq) (*web.LoginResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedPubServant) Version() (*web.VersionResp, mir.Error) { +func (UnimplementedPubServant) Version(c context.Context) (*web.VersionResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/v1/relax.go b/auto/api/v1/relax.go index bc24486cc..b98c07fbb 100644 --- a/auto/api/v1/relax.go +++ b/auto/api/v1/relax.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -18,7 +19,7 @@ type Relax interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain - GetUnreadMsgCount(*web.GetUnreadMsgCountReq) (*web.GetUnreadMsgCountResp, mir.Error) + GetUnreadMsgCount(context.Context, *web.GetUnreadMsgCountReq) (*web.GetUnreadMsgCountResp, mir.Error) mustEmbedUnimplementedRelaxServant() } @@ -54,7 +55,7 @@ func RegisterRelaxServant(e *gin.Engine, s Relax, m ...RelaxChain) { s.Render(c, nil, err) return } - resp, err := s.GetUnreadMsgCount(req) + resp, err := s.GetUnreadMsgCount(c.Request.Context(), req) if err != nil { s.Render(c, nil, err) return @@ -71,7 +72,7 @@ func (UnimplementedRelaxServant) Chain() gin.HandlersChain { return nil } -func (UnimplementedRelaxServant) GetUnreadMsgCount(req *web.GetUnreadMsgCountReq) (*web.GetUnreadMsgCountResp, mir.Error) { +func (UnimplementedRelaxServant) GetUnreadMsgCount(c context.Context, req *web.GetUnreadMsgCountReq) (*web.GetUnreadMsgCountResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/v1/site.go b/auto/api/v1/site.go index 3ec9fcc79..03a4223d1 100644 --- a/auto/api/v1/site.go +++ b/auto/api/v1/site.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -16,8 +17,8 @@ import ( type Site interface { _default_ - Profile() (*conf.WebProfileConf, mir.Error) - Version() (*web.VersionResp, mir.Error) + Profile(context.Context) (*conf.WebProfileConf, mir.Error) + Version(context.Context) (*web.VersionResp, mir.Error) mustEmbedUnimplementedSiteServant() } @@ -34,7 +35,7 @@ func RegisterSiteServant(e *gin.Engine, s Site) { default: } - resp, err := s.Profile() + resp, err := s.Profile(c.Request.Context()) s.Render(c, resp, err) }) router.Handle("GET", "/site/version", func(c *gin.Context) { @@ -44,7 +45,7 @@ func RegisterSiteServant(e *gin.Engine, s Site) { default: } - resp, err := s.Version() + resp, err := s.Version(c.Request.Context()) s.Render(c, resp, err) }) } @@ -52,11 +53,11 @@ func RegisterSiteServant(e *gin.Engine, s Site) { // UnimplementedSiteServant can be embedded to have forward compatible implementations. type UnimplementedSiteServant struct{} -func (UnimplementedSiteServant) Profile() (*conf.WebProfileConf, mir.Error) { +func (UnimplementedSiteServant) Profile(c context.Context) (*conf.WebProfileConf, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedSiteServant) Version() (*web.VersionResp, mir.Error) { +func (UnimplementedSiteServant) Version(c context.Context) (*web.VersionResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/v1/trends.go b/auto/api/v1/trends.go index cce1b7399..3e4836ff8 100644 --- a/auto/api/v1/trends.go +++ b/auto/api/v1/trends.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -18,7 +19,7 @@ type Trends interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain - GetIndexTrends(*web.GetIndexTrendsReq) (*web.GetIndexTrendsResp, mir.Error) + GetIndexTrends(context.Context, *web.GetIndexTrendsReq) (*web.GetIndexTrendsResp, mir.Error) mustEmbedUnimplementedTrendsServant() } @@ -42,7 +43,7 @@ func RegisterTrendsServant(e *gin.Engine, s Trends) { s.Render(c, nil, err) return } - resp, err := s.GetIndexTrends(req) + resp, err := s.GetIndexTrends(c.Request.Context(), req) if err != nil { s.Render(c, nil, err) return @@ -59,7 +60,7 @@ func (UnimplementedTrendsServant) Chain() gin.HandlersChain { return nil } -func (UnimplementedTrendsServant) GetIndexTrends(req *web.GetIndexTrendsReq) (*web.GetIndexTrendsResp, mir.Error) { +func (UnimplementedTrendsServant) GetIndexTrends(c context.Context, req *web.GetIndexTrendsReq) (*web.GetIndexTrendsResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/auto/api/x/v1/user.go b/auto/api/x/v1/user.go index bf2e84a48..405f7d3cd 100644 --- a/auto/api/x/v1/user.go +++ b/auto/api/x/v1/user.go @@ -1,10 +1,11 @@ // Code generated by go-mir. DO NOT EDIT. // versions: -// - mir v4.1.0 +// - mir v4.2.0 package v1 import ( + "context" "net/http" "github.com/alimy/mir/v4" @@ -55,8 +56,8 @@ type User interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain - Logout() mir.Error - Login(*LoginReq) (*LoginResp, mir.Error) + Logout(context.Context) mir.Error + Login(context.Context, *LoginReq) (*LoginResp, mir.Error) mustEmbedUnimplementedUserServant() } @@ -76,7 +77,7 @@ func RegisterUserServant(e *gin.Engine, s User) { default: } - s.Render(c, nil, s.Logout()) + s.Render(c, nil, s.Logout(c.Request.Context())) }) router.Handle("POST", "/user/login/", func(c *gin.Context) { select { @@ -89,7 +90,7 @@ func RegisterUserServant(e *gin.Engine, s User) { s.Render(c, nil, err) return } - resp, err := s.Login(req) + resp, err := s.Login(c.Request.Context(), req) s.Render(c, resp, err) }) } @@ -101,11 +102,11 @@ func (UnimplementedUserServant) Chain() gin.HandlersChain { return nil } -func (UnimplementedUserServant) Logout() mir.Error { +func (UnimplementedUserServant) Logout(c context.Context) mir.Error { return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedUserServant) Login(req *LoginReq) (*LoginResp, mir.Error) { +func (UnimplementedUserServant) Login(c context.Context, req *LoginReq) (*LoginResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/go.mod b/go.mod index 32e98e885..e36ad91a3 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/Masterminds/semver/v3 v3.2.1 github.com/RoaringBitmap/roaring v1.9.0 github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868 - github.com/alimy/mir/v4 v4.1.0 + github.com/alimy/mir/v4 v4.2.0-alpha.1 github.com/alimy/tryst v0.10.1 github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible github.com/allegro/bigcache/v3 v3.1.0 diff --git a/go.sum b/go.sum index 3b1cf38d4..c776b7f37 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/RoaringBitmap/roaring v1.9.0 h1:lwKhr90/j0jVXJyh5X+vQN1VVn77rQFfYnh6R github.com/RoaringBitmap/roaring v1.9.0/go.mod h1:6AXUsoIEzDTFFQCe1RbGA6uFONMhvejWj5rqITANK90= github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868 h1:uFrPOl1VBt/Abfl2z+A/DFc+AwmFLxEHR1+Yq6cXvww= github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868/go.mod h1:srphKZ1i+yGXxl/LpBS7ZIECTjCTPzZzAMtJWoG3sLo= -github.com/alimy/mir/v4 v4.1.0 h1:D6R0dkfsK1iH8MVu0b9yQ0UjdBU09goiui9PVI94G4o= -github.com/alimy/mir/v4 v4.1.0/go.mod h1:d58dBvw2KImcVbAUANrciEV/of0arMNsI9c/5UNCMMc= +github.com/alimy/mir/v4 v4.2.0-alpha.1 h1:PFmKlWnHEpcwFFYfiEkOb8IJJFovhI/5L+VDmYxxkJ0= +github.com/alimy/mir/v4 v4.2.0-alpha.1/go.mod h1:d58dBvw2KImcVbAUANrciEV/of0arMNsI9c/5UNCMMc= github.com/alimy/tryst v0.10.1 h1:ks0CwITNu8VuCBeIxov7acuXWfPn1ySR/FpKbdDOy7A= github.com/alimy/tryst v0.10.1/go.mod h1:6FcqEImav7S62em+p+MODh+stt/UPp23HobUOK3XwFY= github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g= diff --git a/internal/conf/telemetry.go b/internal/conf/telemetry.go index 51b8bcdc7..d00cd31c3 100644 --- a/internal/conf/telemetry.go +++ b/internal/conf/telemetry.go @@ -1,4 +1,4 @@ -// Copyright 2022 ROC. All rights reserved. +// Copyright 2024 ROC. All rights reserved. // Use of this source code is governed by a MIT style // license that can be found in the LICENSE file. diff --git a/internal/model/joint/trace.go b/internal/model/joint/trace.go deleted file mode 100644 index dcfd9a78e..000000000 --- a/internal/model/joint/trace.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2024 ROC. All rights reserved. -// Use of this source code is governed by a MIT style -// license that can be found in the LICENSE file. - -package joint - -import "context" - -type TraceContext interface { - SetContext(c context.Context) - Context() context.Context -} - -type BaseTraceContext struct { - ctx context.Context -} - -func (tc *BaseTraceContext) SetContext(c context.Context) { - tc.ctx = c -} - -func (tc *BaseTraceContext) Context() context.Context { - return tc.ctx -} diff --git a/internal/model/web/admin.go b/internal/model/web/admin.go index 05e766a70..53f8af674 100644 --- a/internal/model/web/admin.go +++ b/internal/model/web/admin.go @@ -4,13 +4,10 @@ package web -import "github.com/rocboss/paopao-ce/internal/model/joint" - type ChangeUserStatusReq struct { - joint.BaseTraceContext `form:"-" binding:"-"` - BaseInfo `json:"-" binding:"-"` - ID int64 `json:"id" form:"id" binding:"required"` - Status int `json:"status" form:"status" binding:"required,oneof=1 2"` + BaseInfo `json:"-" binding:"-"` + ID int64 `json:"id" form:"id" binding:"required"` + Status int `json:"status" form:"status" binding:"required,oneof=1 2"` } type SiteInfoReq struct { diff --git a/internal/model/web/core.go b/internal/model/web/core.go index 30368a761..67a43b6ad 100644 --- a/internal/model/web/core.go +++ b/internal/model/web/core.go @@ -46,8 +46,7 @@ type UserInfoResp struct { } type GetMessagesReq struct { - joint.BaseTraceContext `form:"-" binding:"-"` - SimpleInfo `json:"-" binding:"-"` + SimpleInfo `json:"-" binding:"-"` joint.BasePageInfo Style MessageStyle `form:"style" binding:"required"` } diff --git a/internal/model/web/friendship.go b/internal/model/web/friendship.go index 263db89a4..144f08707 100644 --- a/internal/model/web/friendship.go +++ b/internal/model/web/friendship.go @@ -5,33 +5,28 @@ package web import ( - "github.com/rocboss/paopao-ce/internal/model/joint" "github.com/rocboss/paopao-ce/internal/servants/base" ) type RequestingFriendReq struct { - joint.BaseTraceContext `form:"-" binding:"-"` - BaseInfo `json:"-" binding:"-"` - UserId int64 `json:"user_id" binding:"required"` - Greetings string `json:"greetings" binding:"required"` + BaseInfo `json:"-" binding:"-"` + UserId int64 `json:"user_id" binding:"required"` + Greetings string `json:"greetings" binding:"required"` } type AddFriendReq struct { - joint.BaseTraceContext `form:"-" binding:"-"` - BaseInfo `json:"-" binding:"-"` - UserId int64 `json:"user_id" binding:"required"` + BaseInfo `json:"-" binding:"-"` + UserId int64 `json:"user_id" binding:"required"` } type RejectFriendReq struct { - joint.BaseTraceContext `form:"-" binding:"-"` - BaseInfo `json:"-" binding:"-"` - UserId int64 `json:"user_id" binding:"required"` + BaseInfo `json:"-" binding:"-"` + UserId int64 `json:"user_id" binding:"required"` } type DeleteFriendReq struct { - joint.BaseTraceContext `form:"-" binding:"-"` - BaseInfo `json:"-" binding:"-"` - UserId int64 `json:"user_id"` + BaseInfo `json:"-" binding:"-"` + UserId int64 `json:"user_id"` } type GetContactsReq struct { diff --git a/internal/model/web/loose.go b/internal/model/web/loose.go index dbef6e36a..691bfdf00 100644 --- a/internal/model/web/loose.go +++ b/internal/model/web/loose.go @@ -53,14 +53,13 @@ type TweetCommentsResp struct { } type TimelineReq struct { - joint.BaseTraceContext `form:"-" binding:"-"` - BaseInfo `form:"-" binding:"-"` - Query string `form:"query"` - Visibility []core.PostVisibleT `form:"query"` - Type string `form:"type"` - Style string `form:"style"` - Page int `form:"-" binding:"-"` - PageSize int `form:"-" binding:"-"` + BaseInfo `form:"-" binding:"-"` + Query string `form:"query"` + Visibility []core.PostVisibleT `form:"query"` + Type string `form:"type"` + Style string `form:"style"` + Page int `form:"-" binding:"-"` + PageSize int `form:"-" binding:"-"` } type TimelineResp struct { @@ -68,12 +67,11 @@ type TimelineResp struct { } type GetUserTweetsReq struct { - joint.BaseTraceContext `form:"-" binding:"-"` - BaseInfo `form:"-" binding:"-"` - Username string `form:"username" binding:"required"` - Style string `form:"style"` - Page int `form:"-" binding:"-"` - PageSize int `form:"-" binding:"-"` + BaseInfo `form:"-" binding:"-"` + Username string `form:"username" binding:"required"` + Style string `form:"style"` + Page int `form:"-" binding:"-"` + PageSize int `form:"-" binding:"-"` } type GetUserTweetsResp struct { @@ -134,7 +132,6 @@ func (r *TimelineReq) Bind(c *gin.Context) mir.Error { r.BaseInfo = BaseInfo{ User: user, } - r.SetContext(c.Request.Context()) r.Page, r.PageSize = app.GetPageInfo(c) r.Query, r.Type, r.Style = c.Query("query"), "search", c.Query("style") return nil diff --git a/internal/model/web/priv.go b/internal/model/web/priv.go index 2ffdf928b..cbe38d000 100644 --- a/internal/model/web/priv.go +++ b/internal/model/web/priv.go @@ -124,23 +124,21 @@ type VisibleTweetResp struct { } type CreateCommentReq struct { - joint.BaseTraceContext `json:"-" binding:"-"` - SimpleInfo `json:"-" binding:"-"` - PostID int64 `json:"post_id" binding:"required"` - Contents []*PostContentItem `json:"contents" binding:"required"` - Users []string `json:"users" binding:"required"` - ClientIP string `json:"-" binding:"-"` + SimpleInfo `json:"-" binding:"-"` + PostID int64 `json:"post_id" binding:"required"` + Contents []*PostContentItem `json:"contents" binding:"required"` + Users []string `json:"users" binding:"required"` + ClientIP string `json:"-" binding:"-"` } type CreateCommentResp ms.Comment type CreateCommentReplyReq struct { - joint.BaseTraceContext `form:"-" binding:"-"` - SimpleInfo `json:"-" binding:"-"` - CommentID int64 `json:"comment_id" binding:"required"` - Content string `json:"content" binding:"required"` - AtUserID int64 `json:"at_user_id"` - ClientIP string `json:"-" binding:"-"` + SimpleInfo `json:"-" binding:"-"` + CommentID int64 `json:"comment_id" binding:"required"` + Content string `json:"content" binding:"required"` + AtUserID int64 `json:"at_user_id"` + ClientIP string `json:"-" binding:"-"` } type CreateCommentReplyResp ms.CommentReply diff --git a/internal/servants/base/base.go b/internal/servants/base/base.go index 24629a3f1..7a1b5934e 100644 --- a/internal/servants/base/base.go +++ b/internal/servants/base/base.go @@ -33,45 +33,21 @@ var ( ) func init() { - if conf.UseOpenTelemetry() { - bindAnyFn = func(c *gin.Context, obj any) { - // setup *core.User if needed - if setter, ok := obj.(UserSetter); ok { - user, _ := UserFrom(c) - setter.SetUser(user) - } - // setup UserId if needed - if setter, ok := obj.(UserIdSetter); ok { - uid, _ := UserIdFrom(c) - setter.SetUserId(uid) - } - // setup PageInfo if needed - if setter, ok := obj.(PageInfoSetter); ok { - page, pageSize := app.GetPageInfo(c) - setter.SetPageInfo(page, pageSize) - } + bindAnyFn = func(c *gin.Context, obj any) { + // setup *core.User if needed + if setter, ok := obj.(UserSetter); ok { + user, _ := UserFrom(c) + setter.SetUser(user) } - } else { - bindAnyFn = func(c *gin.Context, obj any) { - // setup *core.User if needed - if setter, ok := obj.(UserSetter); ok { - user, _ := UserFrom(c) - setter.SetUser(user) - } - // setup UserId if needed - if setter, ok := obj.(UserIdSetter); ok { - uid, _ := UserIdFrom(c) - setter.SetUserId(uid) - } - // setup PageInfo if needed - if setter, ok := obj.(PageInfoSetter); ok { - page, pageSize := app.GetPageInfo(c) - setter.SetPageInfo(page, pageSize) - } - // setup trace context if needed - if setter, ok := obj.(joint.TraceContext); ok { - setter.SetContext(c.Request.Context()) - } + // setup UserId if needed + if setter, ok := obj.(UserIdSetter); ok { + uid, _ := UserIdFrom(c) + setter.SetUserId(uid) + } + // setup PageInfo if needed + if setter, ok := obj.(PageInfoSetter); ok { + page, pageSize := app.GetPageInfo(c) + setter.SetPageInfo(page, pageSize) } } } diff --git a/internal/servants/web/admin.go b/internal/servants/web/admin.go index 967b0926e..7327b979f 100644 --- a/internal/servants/web/admin.go +++ b/internal/servants/web/admin.go @@ -5,6 +5,7 @@ package web import ( + "context" "time" "github.com/alimy/mir/v4" @@ -34,8 +35,8 @@ func (s *adminSrv) Chain() gin.HandlersChain { return gin.HandlersChain{chain.JWT(), chain.Admin()} } -func (s *adminSrv) ChangeUserStatus(req *web.ChangeUserStatusReq) mir.Error { - user, err := s.Ds.GetUserByID(req.Context(), req.ID) +func (s *adminSrv) ChangeUserStatus(c context.Context, req *web.ChangeUserStatusReq) mir.Error { + user, err := s.Ds.GetUserByID(c, req.ID) if err != nil || user.Model == nil || user.ID <= 0 { return web.ErrNoExistUsername } @@ -47,7 +48,7 @@ func (s *adminSrv) ChangeUserStatus(req *web.ChangeUserStatusReq) mir.Error { return nil } -func (s *adminSrv) SiteInfo(req *web.SiteInfoReq) (*web.SiteInfoResp, mir.Error) { +func (s *adminSrv) SiteInfo(c context.Context, req *web.SiteInfoReq) (*web.SiteInfoResp, mir.Error) { res, err := &web.SiteInfoResp{ServerUpTime: s.serverUpTime}, error(nil) res.RegisterUserCount, err = s.Ds.GetRegisterUserCount() if err != nil { diff --git a/internal/servants/web/alipay.go b/internal/servants/web/alipay.go index a84a9bd93..d8e96e45b 100644 --- a/internal/servants/web/alipay.go +++ b/internal/servants/web/alipay.go @@ -5,6 +5,7 @@ package web import ( + "context" "fmt" "github.com/alimy/mir/v4" @@ -34,7 +35,7 @@ type alipayPrivSrv struct { alipayClient *alipay.Client } -func (s *alipayPubSrv) AlipayNotify(req *web.AlipayNotifyReq) mir.Error { +func (s *alipayPubSrv) AlipayNotify(c context.Context, req *web.AlipayNotifyReq) mir.Error { if req.TradeStatus == alipay.TradeStatusSuccess { if err := s.Redis.SetRechargeStatus(req.Ctx, req.TradeNo); err == nil { recharge, err := s.Ds.GetRechargeByID(req.ID) @@ -60,7 +61,7 @@ func (s *alipayPrivSrv) Chain() gin.HandlersChain { return gin.HandlersChain{chain.JWT()} } -func (s *alipayPrivSrv) UserWalletBills(req *web.UserWalletBillsReq) (*web.UserWalletBillsResp, mir.Error) { +func (s *alipayPrivSrv) UserWalletBills(c context.Context, req *web.UserWalletBillsReq) (*web.UserWalletBillsResp, mir.Error) { bills, err := s.Ds.GetUserWalletBills(req.UserId, (req.Page-1)*req.PageSize, req.PageSize) if err != nil { logrus.Errorf("GetUserWalletBills err: %s", err) @@ -75,7 +76,7 @@ func (s *alipayPrivSrv) UserWalletBills(req *web.UserWalletBillsReq) (*web.UserW return (*web.UserWalletBillsResp)(resp), nil } -func (s *alipayPrivSrv) UserRechargeLink(req *web.UserRechargeLinkReq) (*web.UserRechargeLinkResp, mir.Error) { +func (s *alipayPrivSrv) UserRechargeLink(c context.Context, req *web.UserRechargeLinkReq) (*web.UserRechargeLinkResp, mir.Error) { recharge, err := s.Ds.CreateRecharge(req.User.ID, req.Amount) if err != nil { logrus.Errorf("Ds.CreateRecharge err: %v", err) @@ -100,7 +101,7 @@ func (s *alipayPrivSrv) UserRechargeLink(req *web.UserRechargeLinkReq) (*web.Use }, nil } -func (s *alipayPrivSrv) UserRechargeResult(req *web.UserRechargeResultReq) (*web.UserRechargeResultResp, mir.Error) { +func (s *alipayPrivSrv) UserRechargeResult(c context.Context, req *web.UserRechargeResultReq) (*web.UserRechargeResultResp, mir.Error) { recharge, err := s.Ds.GetRechargeByID(req.Id) if err != nil { logrus.Errorf("Ds.GetRechargeByID err: %v", err) diff --git a/internal/servants/web/core.go b/internal/servants/web/core.go index 33882b8b0..3e7a52fe2 100644 --- a/internal/servants/web/core.go +++ b/internal/servants/web/core.go @@ -48,7 +48,7 @@ func (s *coreSrv) Chain() gin.HandlersChain { return gin.HandlersChain{chain.JWT()} } -func (s *coreSrv) SyncSearchIndex(req *web.SyncSearchIndexReq) mir.Error { +func (s *coreSrv) SyncSearchIndex(c context.Context, req *web.SyncSearchIndexReq) mir.Error { if req.User != nil && req.User.IsAdmin { s.PushAllPostToSearch() } else { @@ -57,7 +57,7 @@ func (s *coreSrv) SyncSearchIndex(req *web.SyncSearchIndexReq) mir.Error { return nil } -func (s *coreSrv) GetUserInfo(req *web.UserInfoReq) (*web.UserInfoResp, mir.Error) { +func (s *coreSrv) GetUserInfo(c context.Context, req *web.UserInfoReq) (*web.UserInfoResp, mir.Error) { user, err := s.Ds.UserProfileByName(req.Username) if err != nil { logrus.Errorf("coreSrv.GetUserInfo occurs error[1]: %s", err) @@ -86,11 +86,11 @@ func (s *coreSrv) GetUserInfo(req *web.UserInfoReq) (*web.UserInfoResp, mir.Erro return resp, nil } -func (s *coreSrv) GetMessages(req *web.GetMessagesReq) (res *web.GetMessagesResp, _ mir.Error) { +func (s *coreSrv) GetMessages(c context.Context, req *web.GetMessagesReq) (res *web.GetMessagesResp, _ mir.Error) { limit, offset := req.PageSize, (req.Page-1)*req.PageSize // 尝试直接从缓存中获取数据 key, ok := "", false - if res, key, ok = s.messagesFromCache(req, limit, offset); ok { + if res, key, ok = s.messagesFromCache(c, req, limit, offset); ok { // logrus.Debugf("coreSrv.GetMessages from cache key:%s", key) return } @@ -102,12 +102,12 @@ func (s *coreSrv) GetMessages(req *web.GetMessagesReq) (res *web.GetMessagesResp for _, mf := range messages { // TODO: 优化处理这里的user获取逻辑以及错误处理 if mf.SenderUserID > 0 { - if user, err := s.Ds.GetUserByID(req.Context(), mf.SenderUserID); err == nil { + if user, err := s.Ds.GetUserByID(c, mf.SenderUserID); err == nil { mf.SenderUser = user.Format() } } if mf.Type == ms.MsgTypeWhisper && mf.ReceiverUserID != req.Uid { - if user, err := s.Ds.GetUserByID(req.Context(), mf.ReceiverUserID); err == nil { + if user, err := s.Ds.GetUserByID(c, mf.ReceiverUserID); err == nil { mf.ReceiverUser = user.Format() } } @@ -152,7 +152,7 @@ func (s *coreSrv) GetMessages(req *web.GetMessagesReq) (res *web.GetMessagesResp }, nil } -func (s *coreSrv) ReadMessage(req *web.ReadMessageReq) mir.Error { +func (s *coreSrv) ReadMessage(c context.Context, req *web.ReadMessageReq) mir.Error { message, err := s.Ds.GetMessageByID(req.ID) if err != nil { return web.ErrReadMessageFailed @@ -169,7 +169,7 @@ func (s *coreSrv) ReadMessage(req *web.ReadMessageReq) mir.Error { return nil } -func (s *coreSrv) ReadAllMessage(req *web.ReadAllMessageReq) mir.Error { +func (s *coreSrv) ReadAllMessage(c context.Context, req *web.ReadAllMessageReq) mir.Error { if err := s.Ds.ReadAllMessage(req.Uid); err != nil { logrus.Errorf("coreSrv.Ds.ReadAllMessage err: %s", err) return web.ErrReadMessageFailed @@ -179,7 +179,7 @@ func (s *coreSrv) ReadAllMessage(req *web.ReadAllMessageReq) mir.Error { return nil } -func (s *coreSrv) SendUserWhisper(req *web.SendWhisperReq) mir.Error { +func (s *coreSrv) SendUserWhisper(c context.Context, req *web.SendWhisperReq) mir.Error { // 不允许发送私信给自己 if req.Uid == req.UserID { return web.ErrNoWhisperToSelf @@ -209,7 +209,7 @@ func (s *coreSrv) SendUserWhisper(req *web.SendWhisperReq) mir.Error { return nil } -func (s *coreSrv) GetCollections(req *web.GetCollectionsReq) (*web.GetCollectionsResp, mir.Error) { +func (s *coreSrv) GetCollections(c context.Context, req *web.GetCollectionsReq) (*web.GetCollectionsResp, mir.Error) { collections, err := s.Ds.GetUserPostCollections(req.UserId, (req.Page-1)*req.PageSize, req.PageSize) if err != nil { logrus.Errorf("Ds.GetUserPostCollections err: %s", err) @@ -237,7 +237,7 @@ func (s *coreSrv) GetCollections(req *web.GetCollectionsReq) (*web.GetCollection return (*web.GetCollectionsResp)(resp), nil } -func (s *coreSrv) UserPhoneBind(req *web.UserPhoneBindReq) mir.Error { +func (s *coreSrv) UserPhoneBind(c context.Context, req *web.UserPhoneBindReq) mir.Error { // 手机重复性检查 u, err := s.Ds.GetUserByPhone(req.Phone) if err == nil && u.Model != nil && u.ID != 0 && u.ID != req.User.ID { @@ -274,7 +274,7 @@ func (s *coreSrv) UserPhoneBind(req *web.UserPhoneBindReq) mir.Error { return nil } -func (s *coreSrv) GetStars(req *web.GetStarsReq) (*web.GetStarsResp, mir.Error) { +func (s *coreSrv) GetStars(c context.Context, req *web.GetStarsReq) (*web.GetStarsResp, mir.Error) { stars, err := s.Ds.GetUserPostStars(req.UserId, req.PageSize, (req.Page-1)*req.PageSize) if err != nil { logrus.Errorf("Ds.GetUserPostStars err: %s", err) @@ -298,7 +298,7 @@ func (s *coreSrv) GetStars(req *web.GetStarsReq) (*web.GetStarsResp, mir.Error) return (*web.GetStarsResp)(resp), nil } -func (s *coreSrv) ChangePassword(req *web.ChangePasswordReq) mir.Error { +func (s *coreSrv) ChangePassword(c context.Context, req *web.ChangePasswordReq) mir.Error { // 密码检查 if err := checkPassword(req.Password); err != nil { return err @@ -317,7 +317,7 @@ func (s *coreSrv) ChangePassword(req *web.ChangePasswordReq) mir.Error { return nil } -func (s *coreSrv) SuggestTags(req *web.SuggestTagsReq) (*web.SuggestTagsResp, mir.Error) { +func (s *coreSrv) SuggestTags(c context.Context, req *web.SuggestTagsReq) (*web.SuggestTagsResp, mir.Error) { tags, err := s.Ds.TagsByKeyword(req.Keyword) if err != nil { logrus.Errorf("Ds.GetTagsByKeyword err: %s", err) @@ -330,7 +330,7 @@ func (s *coreSrv) SuggestTags(req *web.SuggestTagsReq) (*web.SuggestTagsResp, mi return resp, nil } -func (s *coreSrv) SuggestUsers(req *web.SuggestUsersReq) (*web.SuggestUsersResp, mir.Error) { +func (s *coreSrv) SuggestUsers(c context.Context, req *web.SuggestUsersReq) (*web.SuggestUsersResp, mir.Error) { users, err := s.Ds.GetUsersByKeyword(req.Keyword) if err != nil { logrus.Errorf("Ds.GetUsersByKeyword err: %s", err) @@ -343,7 +343,7 @@ func (s *coreSrv) SuggestUsers(req *web.SuggestUsersReq) (*web.SuggestUsersResp, return resp, nil } -func (s *coreSrv) ChangeNickname(req *web.ChangeNicknameReq) mir.Error { +func (s *coreSrv) ChangeNickname(c context.Context, req *web.ChangeNicknameReq) mir.Error { if utf8.RuneCountInString(req.Nickname) < 2 || utf8.RuneCountInString(req.Nickname) > 12 { return web.ErrNicknameLengthLimit } @@ -358,7 +358,7 @@ func (s *coreSrv) ChangeNickname(req *web.ChangeNicknameReq) mir.Error { return nil } -func (s *coreSrv) ChangeAvatar(req *web.ChangeAvatarReq) (xerr mir.Error) { +func (s *coreSrv) ChangeAvatar(c context.Context, req *web.ChangeAvatarReq) (xerr mir.Error) { defer func() { if xerr != nil { deleteOssObjects(s.oss, []string{req.Avatar}) @@ -384,7 +384,7 @@ func (s *coreSrv) ChangeAvatar(req *web.ChangeAvatarReq) (xerr mir.Error) { return nil } -func (s *coreSrv) TweetCollectionStatus(req *web.TweetCollectionStatusReq) (*web.TweetCollectionStatusResp, mir.Error) { +func (s *coreSrv) TweetCollectionStatus(c context.Context, req *web.TweetCollectionStatusReq) (*web.TweetCollectionStatusResp, mir.Error) { resp := &web.TweetCollectionStatusResp{ Status: true, } @@ -395,7 +395,7 @@ func (s *coreSrv) TweetCollectionStatus(req *web.TweetCollectionStatusReq) (*web return resp, nil } -func (s *coreSrv) TweetStarStatus(req *web.TweetStarStatusReq) (*web.TweetStarStatusResp, mir.Error) { +func (s *coreSrv) TweetStarStatus(c context.Context, req *web.TweetStarStatusReq) (*web.TweetStarStatusResp, mir.Error) { resp := &web.TweetStarStatusResp{ Status: true, } @@ -406,7 +406,7 @@ func (s *coreSrv) TweetStarStatus(req *web.TweetStarStatusReq) (*web.TweetStarSt return resp, nil } -func (s *coreSrv) messagesFromCache(req *web.GetMessagesReq, limit int, offset int) (res *web.GetMessagesResp, key string, ok bool) { +func (s *coreSrv) messagesFromCache(c context.Context, req *web.GetMessagesReq, limit int, offset int) (res *web.GetMessagesResp, key string, ok bool) { key = fmt.Sprintf("%s%d:%s:%d:%d", s.prefixMessages, req.Uid, req.Style, limit, offset) if data, err := s.wc.Get(key); err == nil { ok, res = true, &web.GetMessagesResp{ diff --git a/internal/servants/web/followship.go b/internal/servants/web/followship.go index 0344841a6..64d1e247a 100644 --- a/internal/servants/web/followship.go +++ b/internal/servants/web/followship.go @@ -5,6 +5,8 @@ package web import ( + "context" + "github.com/alimy/mir/v4" "github.com/gin-gonic/gin" api "github.com/rocboss/paopao-ce/auto/api/v1" @@ -29,7 +31,7 @@ func (s *followshipSrv) Chain() gin.HandlersChain { return gin.HandlersChain{chain.JwtLoose()} } -func (s *followshipSrv) ListFollowings(r *web.ListFollowingsReq) (*web.ListFollowingsResp, mir.Error) { +func (s *followshipSrv) ListFollowings(c context.Context, r *web.ListFollowingsReq) (*web.ListFollowingsResp, mir.Error) { he, err := s.Ds.GetUserByUsername(r.Username) if err != nil { logrus.Errorf("Ds.GetUserByUsername err: %s", err) @@ -49,7 +51,7 @@ func (s *followshipSrv) ListFollowings(r *web.ListFollowingsReq) (*web.ListFollo return (*web.ListFollowingsResp)(resp), nil } -func (s *followshipSrv) ListFollows(r *web.ListFollowsReq) (*web.ListFollowsResp, mir.Error) { +func (s *followshipSrv) ListFollows(c context.Context, r *web.ListFollowsReq) (*web.ListFollowsResp, mir.Error) { he, err := s.Ds.GetUserByUsername(r.Username) if err != nil { logrus.Errorf("Ds.GetUserByUsername err: %s", err) @@ -75,7 +77,7 @@ func (s *followshipSrv) ListFollows(r *web.ListFollowsReq) (*web.ListFollowsResp return (*web.ListFollowsResp)(resp), nil } -func (s *followshipSrv) UnfollowUser(r *web.UnfollowUserReq) mir.Error { +func (s *followshipSrv) UnfollowUser(c context.Context, r *web.UnfollowUserReq) mir.Error { if r.User == nil { return xerror.UnauthorizedTokenError } else if r.User.ID == r.UserId { @@ -94,7 +96,7 @@ func (s *followshipSrv) UnfollowUser(r *web.UnfollowUserReq) mir.Error { return nil } -func (s *followshipSrv) FollowUser(r *web.FollowUserReq) mir.Error { +func (s *followshipSrv) FollowUser(c context.Context, r *web.FollowUserReq) mir.Error { if r.User == nil { return xerror.UnauthorizedTokenError } else if r.User.ID == r.UserId { diff --git a/internal/servants/web/friendship.go b/internal/servants/web/friendship.go index a9a179ac0..24143eb6b 100644 --- a/internal/servants/web/friendship.go +++ b/internal/servants/web/friendship.go @@ -5,6 +5,8 @@ package web import ( + "context" + "github.com/alimy/mir/v4" "github.com/gin-gonic/gin" api "github.com/rocboss/paopao-ce/auto/api/v1" @@ -28,7 +30,7 @@ func (s *friendshipSrv) Chain() gin.HandlersChain { return gin.HandlersChain{chain.JWT()} } -func (s *friendshipSrv) GetContacts(req *web.GetContactsReq) (*web.GetContactsResp, mir.Error) { +func (s *friendshipSrv) GetContacts(c context.Context, req *web.GetContactsReq) (*web.GetContactsResp, mir.Error) { if req.User == nil { return nil, xerror.ServerError } @@ -41,14 +43,14 @@ func (s *friendshipSrv) GetContacts(req *web.GetContactsReq) (*web.GetContactsRe return (*web.GetContactsResp)(resp), nil } -func (s *friendshipSrv) DeleteFriend(req *web.DeleteFriendReq) mir.Error { +func (s *friendshipSrv) DeleteFriend(c context.Context, req *web.DeleteFriendReq) mir.Error { if req.User == nil { return xerror.ServerError } if req.User != nil && req.User.ID == req.UserId { return web.ErrNoActionToSelf } - if _, err := s.Ds.GetUserByID(req.Context(), req.UserId); err != nil { + if _, err := s.Ds.GetUserByID(c, req.UserId); err != nil { return web.ErrNotExistFriendId } if err := s.Ds.DeleteFriend(req.User.ID, req.UserId); err != nil { @@ -61,14 +63,14 @@ func (s *friendshipSrv) DeleteFriend(req *web.DeleteFriendReq) mir.Error { return nil } -func (s *friendshipSrv) RejectFriend(req *web.RejectFriendReq) mir.Error { +func (s *friendshipSrv) RejectFriend(c context.Context, req *web.RejectFriendReq) mir.Error { if req.User == nil { return xerror.ServerError } if req.User.ID == req.UserId { return web.ErrNoActionToSelf } - if _, err := s.Ds.GetUserByID(req.Context(), req.UserId); err != nil { + if _, err := s.Ds.GetUserByID(c, req.UserId); err != nil { return web.ErrNotExistFriendId } if err := s.Ds.RejectFriend(req.User.ID, req.UserId); err != nil { @@ -78,14 +80,14 @@ func (s *friendshipSrv) RejectFriend(req *web.RejectFriendReq) mir.Error { return nil } -func (s *friendshipSrv) AddFriend(req *web.AddFriendReq) mir.Error { +func (s *friendshipSrv) AddFriend(c context.Context, req *web.AddFriendReq) mir.Error { if req.User == nil { return xerror.ServerError } if req.User.ID == req.UserId { return web.ErrNoActionToSelf } - if _, err := s.Ds.GetUserByID(req.Context(), req.UserId); err != nil { + if _, err := s.Ds.GetUserByID(c, req.UserId); err != nil { return web.ErrNotExistFriendId } if err := s.Ds.AddFriend(req.User.ID, req.UserId); err != nil { @@ -98,14 +100,14 @@ func (s *friendshipSrv) AddFriend(req *web.AddFriendReq) mir.Error { return nil } -func (s *friendshipSrv) RequestingFriend(req *web.RequestingFriendReq) mir.Error { +func (s *friendshipSrv) RequestingFriend(c context.Context, req *web.RequestingFriendReq) mir.Error { if req.User == nil { return xerror.ServerError } if req.User.ID == req.UserId { return web.ErrNoRequestingFriendToSelf } - if _, err := s.Ds.GetUserByID(req.Context(), req.UserId); err != nil { + if _, err := s.Ds.GetUserByID(c, req.UserId); err != nil { return web.ErrNotExistFriendId } if err := s.Ds.RequestingFriend(req.User.ID, req.UserId, req.Greetings); err != nil { diff --git a/internal/servants/web/loose.go b/internal/servants/web/loose.go index a70fcf826..0b7a88f6b 100644 --- a/internal/servants/web/loose.go +++ b/internal/servants/web/loose.go @@ -5,6 +5,7 @@ package web import ( + "context" "fmt" "github.com/alimy/mir/v4" @@ -51,17 +52,16 @@ func (s *looseSrv) Chain() gin.HandlersChain { return gin.HandlersChain{chain.JwtLoose()} } -func (s *traceLooseSrv) Timeline(req *web.TimelineReq) (*web.TimelineResp, mir.Error) { - ctx, span := s.tracer.Start(req.Context(), "looseSrv.Timeline") +func (s *traceLooseSrv) Timeline(c context.Context, req *web.TimelineReq) (*web.TimelineResp, mir.Error) { + ctx, span := s.tracer.Start(c, "looseSrv.Timeline") defer span.End() - req.SetContext(ctx) - return s.looseSrv.Timeline(req) + return s.looseSrv.Timeline(ctx, req) } -func (s *looseSrv) Timeline(req *web.TimelineReq) (*web.TimelineResp, mir.Error) { +func (s *looseSrv) Timeline(c context.Context, req *web.TimelineReq) (*web.TimelineResp, mir.Error) { limit, offset := req.PageSize, (req.Page-1)*req.PageSize if req.Query == "" && req.Type == "search" { - return s.getIndexTweets(req, limit, offset) + return s.getIndexTweets(c, req, limit, offset) } q := &core.QueryReq{ Query: req.Query, @@ -93,12 +93,10 @@ func (s *looseSrv) Timeline(req *web.TimelineReq) (*web.TimelineResp, mir.Error) }, nil } -func (s *looseSrv) getIndexTweets(req *web.TimelineReq, limit int, offset int) (res *web.TimelineResp, err mir.Error) { - ctx := req.Context() - +func (s *looseSrv) getIndexTweets(c context.Context, req *web.TimelineReq, limit int, offset int) (res *web.TimelineResp, err mir.Error) { // 尝试直接从缓存中获取数据 key, ok := "", false - if res, key, ok = s.indexTweetsFromCache(req, limit, offset); ok { + if res, key, ok = s.indexTweetsFromCache(c, req, limit, offset); ok { // logrus.WithContext(ctx).WithField("key", key).Debug("getIndexTweets from cache") return } @@ -111,26 +109,26 @@ func (s *looseSrv) getIndexTweets(req *web.TimelineReq, limit int, offset int) ( switch req.Style { case web.StyleTweetsFollowing: if req.User != nil { - posts, total, xerr = s.Ds.ListFollowingTweets(ctx, req.User.ID, limit, offset) + posts, total, xerr = s.Ds.ListFollowingTweets(c, req.User.ID, limit, offset) } else { // return nil, web.ErrGetPostsNilUser // 宽松处理,前端退出登录后马上获取动态列表,可能错误走到这里 - posts, total, xerr = s.Ds.ListIndexNewestTweets(ctx, limit, offset) + posts, total, xerr = s.Ds.ListIndexNewestTweets(c, limit, offset) } case web.StyleTweetsNewest: - posts, total, xerr = s.Ds.ListIndexNewestTweets(ctx, limit, offset) + posts, total, xerr = s.Ds.ListIndexNewestTweets(c, limit, offset) case web.StyleTweetsHots: - posts, total, xerr = s.Ds.ListIndexHotsTweets(ctx, limit, offset) + posts, total, xerr = s.Ds.ListIndexHotsTweets(c, limit, offset) default: return nil, web.ErrGetPostsUnknowStyle } if xerr != nil { - logrus.WithContext(ctx).Errorf("getIndexTweets occurs error[1]: %s", xerr) + logrus.WithContext(c).Errorf("getIndexTweets occurs error[1]: %s", xerr) return nil, web.ErrGetPostFailed } postsFormated, verr := s.Ds.MergePosts(posts) if verr != nil { - logrus.WithContext(ctx).Errorf("getIndexTweets in merge posts occurs error: %s", verr) + logrus.WithContext(c).Errorf("getIndexTweets in merge posts occurs error: %s", verr) return nil, web.ErrGetPostFailed } userId := int64(-1) @@ -138,7 +136,7 @@ func (s *looseSrv) getIndexTweets(req *web.TimelineReq, limit int, offset int) ( userId = req.User.ID } if err := s.PrepareTweets(userId, postsFormated); err != nil { - logrus.WithContext(ctx).Errorf("getIndexTweets occurs error[2]: %s", err) + logrus.WithContext(c).Errorf("getIndexTweets occurs error[2]: %s", err) return nil, web.ErrGetPostsFailed } resp := joint.PageRespFrom(postsFormated, req.Page, req.PageSize, total) @@ -151,7 +149,7 @@ func (s *looseSrv) getIndexTweets(req *web.TimelineReq, limit int, offset int) ( }, nil } -func (s *looseSrv) indexTweetsFromCache(req *web.TimelineReq, limit int, offset int) (res *web.TimelineResp, key string, ok bool) { +func (s *looseSrv) indexTweetsFromCache(c context.Context, req *web.TimelineReq, limit int, offset int) (res *web.TimelineResp, key string, ok bool) { username := "_" if req.User != nil { username = req.User.Username @@ -176,7 +174,7 @@ func (s *looseSrv) indexTweetsFromCache(req *web.TimelineReq, limit int, offset return } -func (s *looseSrv) tweetCommentsFromCache(req *web.TweetCommentsReq, limit int, offset int) (res *web.TweetCommentsResp, key string, ok bool) { +func (s *looseSrv) tweetCommentsFromCache(c context.Context, req *web.TweetCommentsReq, limit int, offset int) (res *web.TweetCommentsResp, key string, ok bool) { key = fmt.Sprintf("%s%d:%s:%d:%d", s.prefixTweetComment, req.TweetId, req.Style, limit, offset) if data, err := s.ac.Get(key); err == nil { ok, res = true, &web.TweetCommentsResp{ @@ -188,36 +186,35 @@ func (s *looseSrv) tweetCommentsFromCache(req *web.TweetCommentsReq, limit int, return } -func (s *traceLooseSrv) GetUserTweets(req *web.GetUserTweetsReq) (res *web.GetUserTweetsResp, err mir.Error) { - ctx, span := s.tracer.Start(req.Context(), "looseSrv.GetUserTweets") +func (s *traceLooseSrv) GetUserTweets(c context.Context, req *web.GetUserTweetsReq) (res *web.GetUserTweetsResp, err mir.Error) { + ctx, span := s.tracer.Start(c, "looseSrv.GetUserTweets") defer span.End() - req.SetContext(ctx) - return s.looseSrv.GetUserTweets(req) + return s.looseSrv.GetUserTweets(ctx, req) } -func (s *looseSrv) GetUserTweets(req *web.GetUserTweetsReq) (res *web.GetUserTweetsResp, err mir.Error) { +func (s *looseSrv) GetUserTweets(c context.Context, req *web.GetUserTweetsReq) (res *web.GetUserTweetsResp, err mir.Error) { user, xerr := s.RelationTypFrom(req.User, req.Username) if xerr != nil { return nil, err } // 尝试直接从缓存中获取数据 key, ok := "", false - if res, key, ok = s.userTweetsFromCache(req, user); ok { + if res, key, ok = s.userTweetsFromCache(c, req, user); ok { // logrus.Debugf("GetUserTweets from cache key:%s", key) return } // 缓存获取未成功,只能查库了 switch req.Style { case web.UserPostsStyleComment, web.UserPostsStyleMedia: - res, err = s.listUserTweets(req, user) + res, err = s.listUserTweets(c, req, user) case web.UserPostsStyleHighlight: - res, err = s.getUserPostTweets(req, user, true) + res, err = s.getUserPostTweets(c, req, user, true) case web.UserPostsStyleStar: - res, err = s.getUserStarTweets(req, user) + res, err = s.getUserStarTweets(c, req, user) case web.UserPostsStylePost: fallthrough default: - res, err = s.getUserPostTweets(req, user, false) + res, err = s.getUserPostTweets(c, req, user, false) } // 缓存处理 if err == nil { @@ -226,7 +223,7 @@ func (s *looseSrv) GetUserTweets(req *web.GetUserTweetsReq) (res *web.GetUserTwe return } -func (s *looseSrv) userTweetsFromCache(req *web.GetUserTweetsReq, user *cs.VistUser) (res *web.GetUserTweetsResp, key string, ok bool) { +func (s *looseSrv) userTweetsFromCache(c context.Context, req *web.GetUserTweetsReq, user *cs.VistUser) (res *web.GetUserTweetsResp, key string, ok bool) { switch req.Style { case web.UserPostsStylePost, web.UserPostsStyleHighlight, web.UserPostsStyleMedia: key = fmt.Sprintf("%s%d:%s:%s:%d:%d", s.prefixUserTweets, user.UserId, req.Style, user.RelTyp, req.Page, req.PageSize) @@ -247,7 +244,7 @@ func (s *looseSrv) userTweetsFromCache(req *web.GetUserTweetsReq, user *cs.VistU return } -func (s *looseSrv) getUserStarTweets(req *web.GetUserTweetsReq, user *cs.VistUser) (*web.GetUserTweetsResp, mir.Error) { +func (s *looseSrv) getUserStarTweets(c context.Context, req *web.GetUserTweetsReq, user *cs.VistUser) (*web.GetUserTweetsResp, mir.Error) { stars, totalRows, err := s.Ds.ListUserStarTweets(user, req.PageSize, (req.Page-1)*req.PageSize) if err != nil { logrus.Errorf("getUserStarTweets err[1]: %s", err) @@ -280,7 +277,7 @@ func (s *looseSrv) getUserStarTweets(req *web.GetUserTweetsReq, user *cs.VistUse }, nil } -func (s *looseSrv) listUserTweets(req *web.GetUserTweetsReq, user *cs.VistUser) (*web.GetUserTweetsResp, mir.Error) { +func (s *looseSrv) listUserTweets(c context.Context, req *web.GetUserTweetsReq, user *cs.VistUser) (*web.GetUserTweetsResp, mir.Error) { var ( tweets []*ms.Post total int64 @@ -319,7 +316,7 @@ func (s *looseSrv) listUserTweets(req *web.GetUserTweetsReq, user *cs.VistUser) }, nil } -func (s *looseSrv) getUserPostTweets(req *web.GetUserTweetsReq, user *cs.VistUser, isHighlight bool) (*web.GetUserTweetsResp, mir.Error) { +func (s *looseSrv) getUserPostTweets(c context.Context, req *web.GetUserTweetsReq, user *cs.VistUser, isHighlight bool) (*web.GetUserTweetsResp, mir.Error) { style := cs.StyleUserTweetsGuest switch user.RelTyp { case cs.RelationAdmin: @@ -361,7 +358,7 @@ func (s *looseSrv) getUserPostTweets(req *web.GetUserTweetsReq, user *cs.VistUse }, nil } -func (s *looseSrv) GetUserProfile(req *web.GetUserProfileReq) (*web.GetUserProfileResp, mir.Error) { +func (s *looseSrv) GetUserProfile(c context.Context, req *web.GetUserProfileReq) (*web.GetUserProfileResp, mir.Error) { he, err := s.Ds.UserProfileByName(req.Username) if err != nil { logrus.Errorf("looseSrv.GetUserProfile occurs error[1]: %s", err) @@ -396,7 +393,7 @@ func (s *looseSrv) GetUserProfile(req *web.GetUserProfileReq) (*web.GetUserProfi }, nil } -func (s *looseSrv) TopicList(req *web.TopicListReq) (*web.TopicListResp, mir.Error) { +func (s *looseSrv) TopicList(c context.Context, req *web.TopicListReq) (*web.TopicListResp, mir.Error) { var ( tags, extralTags cs.TagList err error @@ -433,11 +430,11 @@ func (s *looseSrv) TopicList(req *web.TopicListReq) (*web.TopicListResp, mir.Err }, nil } -func (s *looseSrv) TweetComments(req *web.TweetCommentsReq) (res *web.TweetCommentsResp, err mir.Error) { +func (s *looseSrv) TweetComments(c context.Context, req *web.TweetCommentsReq) (res *web.TweetCommentsResp, err mir.Error) { limit, offset := req.PageSize, (req.Page-1)*req.PageSize // 尝试直接从缓存中获取数据 key, ok := "", false - if res, key, ok = s.tweetCommentsFromCache(req, limit, offset); ok { + if res, key, ok = s.tweetCommentsFromCache(c, req, limit, offset); ok { logrus.Debugf("looseSrv.TweetComments from cache key:%s", key) return } @@ -527,7 +524,7 @@ func (s *looseSrv) TweetComments(req *web.TweetCommentsReq) (res *web.TweetComme }, nil } -func (s *looseSrv) TweetDetail(req *web.TweetDetailReq) (*web.TweetDetailResp, mir.Error) { +func (s *looseSrv) TweetDetail(c context.Context, req *web.TweetDetailReq) (*web.TweetDetailResp, mir.Error) { post, err := s.Ds.GetPostByID(req.TweetId) if err != nil { return nil, web.ErrGetPostFailed diff --git a/internal/servants/web/priv.go b/internal/servants/web/priv.go index 3d11ce178..eb356d853 100644 --- a/internal/servants/web/priv.go +++ b/internal/servants/web/priv.go @@ -5,6 +5,7 @@ package web import ( + "context" "image" "io" "strings" @@ -62,7 +63,7 @@ func (s *privSrv) Chain() gin.HandlersChain { return gin.HandlersChain{chain.JWT(), chain.Priv()} } -func (s *privSrv) ThumbsDownTweetReply(req *web.TweetReplyThumbsReq) mir.Error { +func (s *privSrv) ThumbsDownTweetReply(c context.Context, req *web.TweetReplyThumbsReq) mir.Error { if err := s.Ds.ThumbsDownReply(req.Uid, req.TweetId, req.CommentId, req.ReplyId); err != nil { logrus.Errorf("thumbs down tweet reply error: %s req:%v", err, req) return web.ErrThumbsDownTweetReply @@ -70,7 +71,7 @@ func (s *privSrv) ThumbsDownTweetReply(req *web.TweetReplyThumbsReq) mir.Error { return nil } -func (s *privSrv) ThumbsUpTweetReply(req *web.TweetReplyThumbsReq) mir.Error { +func (s *privSrv) ThumbsUpTweetReply(c context.Context, req *web.TweetReplyThumbsReq) mir.Error { if err := s.Ds.ThumbsUpReply(req.Uid, req.TweetId, req.CommentId, req.ReplyId); err != nil { logrus.Errorf("thumbs up tweet reply error: %s req:%v", err, req) return web.ErrThumbsUpTweetReply @@ -78,7 +79,7 @@ func (s *privSrv) ThumbsUpTweetReply(req *web.TweetReplyThumbsReq) mir.Error { return nil } -func (s *privSrv) ThumbsDownTweetComment(req *web.TweetCommentThumbsReq) mir.Error { +func (s *privSrv) ThumbsDownTweetComment(c context.Context, req *web.TweetCommentThumbsReq) mir.Error { if err := s.Ds.ThumbsDownComment(req.Uid, req.TweetId, req.CommentId); err != nil { logrus.Errorf("thumbs down tweet comment error: %s req:%v", err, req) return web.ErrThumbsDownTweetComment @@ -88,7 +89,7 @@ func (s *privSrv) ThumbsDownTweetComment(req *web.TweetCommentThumbsReq) mir.Err return nil } -func (s *privSrv) ThumbsUpTweetComment(req *web.TweetCommentThumbsReq) mir.Error { +func (s *privSrv) ThumbsUpTweetComment(c context.Context, req *web.TweetCommentThumbsReq) mir.Error { if err := s.Ds.ThumbsUpComment(req.Uid, req.TweetId, req.CommentId); err != nil { logrus.Errorf("thumbs up tweet comment error: %s req:%v", err, req) return web.ErrThumbsUpTweetComment @@ -98,7 +99,7 @@ func (s *privSrv) ThumbsUpTweetComment(req *web.TweetCommentThumbsReq) mir.Error return nil } -func (s *privSrv) UnfollowTopic(req *web.UnfollowTopicReq) mir.Error { +func (s *privSrv) UnfollowTopic(c context.Context, req *web.UnfollowTopicReq) mir.Error { if err := s.Ds.UnfollowTopic(req.Uid, req.TopicId); err != nil { logrus.Errorf("user(%d) unfollow topic(%d) failed: %s", req.Uid, req.TopicId, err) return web.ErrUnfollowTopicFailed @@ -106,7 +107,7 @@ func (s *privSrv) UnfollowTopic(req *web.UnfollowTopicReq) mir.Error { return nil } -func (s *privSrv) FollowTopic(req *web.FollowTopicReq) mir.Error { +func (s *privSrv) FollowTopic(c context.Context, req *web.FollowTopicReq) mir.Error { if err := s.Ds.FollowTopic(req.Uid, req.TopicId); err != nil { logrus.Errorf("user(%d) follow topic(%d) failed: %s", req.Uid, req.TopicId, err) return web.ErrFollowTopicFailed @@ -114,7 +115,7 @@ func (s *privSrv) FollowTopic(req *web.FollowTopicReq) mir.Error { return nil } -func (s *privSrv) StickTopic(req *web.StickTopicReq) (*web.StickTopicResp, mir.Error) { +func (s *privSrv) StickTopic(c context.Context, req *web.StickTopicReq) (*web.StickTopicResp, mir.Error) { status, err := s.Ds.StickTopic(req.Uid, req.TopicId) if err != nil { logrus.Errorf("user(%d) stick topic(%d) failed: %s", req.Uid, req.TopicId, err) @@ -125,7 +126,7 @@ func (s *privSrv) StickTopic(req *web.StickTopicReq) (*web.StickTopicResp, mir.E }, nil } -func (s *privSrv) PinTopic(req *web.PinTopicReq) (*web.PinTopicResp, mir.Error) { +func (s *privSrv) PinTopic(c context.Context, req *web.PinTopicReq) (*web.PinTopicResp, mir.Error) { status, err := s.Ds.PinTopic(req.Uid, req.TopicId) if err != nil { logrus.Errorf("user(%d) pin topic(%d) failed: %s", req.Uid, req.TopicId, err) @@ -136,7 +137,7 @@ func (s *privSrv) PinTopic(req *web.PinTopicReq) (*web.PinTopicResp, mir.Error) }, nil } -func (s *privSrv) UploadAttachment(req *web.UploadAttachmentReq) (*web.UploadAttachmentResp, mir.Error) { +func (s *privSrv) UploadAttachment(c context.Context, req *web.UploadAttachmentReq) (*web.UploadAttachmentResp, mir.Error) { defer req.File.Close() // 生成随机路径 @@ -182,7 +183,7 @@ func (s *privSrv) UploadAttachment(req *web.UploadAttachmentReq) (*web.UploadAtt }, nil } -func (s *privSrv) DownloadAttachmentPrecheck(req *web.DownloadAttachmentPrecheckReq) (*web.DownloadAttachmentPrecheckResp, mir.Error) { +func (s *privSrv) DownloadAttachmentPrecheck(c context.Context, req *web.DownloadAttachmentPrecheckReq) (*web.DownloadAttachmentPrecheckResp, mir.Error) { content, err := s.Ds.GetPostContentByID(req.ContentID) if err != nil { logrus.Errorf("Ds.GetPostContentByID err: %s", err) @@ -205,7 +206,7 @@ func (s *privSrv) DownloadAttachmentPrecheck(req *web.DownloadAttachmentPrecheck return resp, nil } -func (s *privSrv) DownloadAttachment(req *web.DownloadAttachmentReq) (*web.DownloadAttachmentResp, mir.Error) { +func (s *privSrv) DownloadAttachment(c context.Context, req *web.DownloadAttachmentReq) (*web.DownloadAttachmentResp, mir.Error) { content, err := s.Ds.GetPostContentByID(req.ContentID) if err != nil { logrus.Errorf("s.GetPostContentByID err: %v", err) @@ -249,7 +250,7 @@ func (s *privSrv) DownloadAttachment(req *web.DownloadAttachmentReq) (*web.Downl }, nil } -func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp, xerr mir.Error) { +func (s *privSrv) CreateTweet(c context.Context, req *web.CreateTweetReq) (_ *web.CreateTweetResp, xerr mir.Error) { var mediaContents []string defer func() { if xerr != nil { @@ -336,7 +337,7 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp, return (*web.CreateTweetResp)(formatedPosts[0]), nil } -func (s *privSrv) DeleteTweet(req *web.DeleteTweetReq) mir.Error { +func (s *privSrv) DeleteTweet(c context.Context, req *web.DeleteTweetReq) mir.Error { if req.User == nil { return web.ErrNoPermission } @@ -368,7 +369,7 @@ func (s *privSrv) DeleteTweet(req *web.DeleteTweetReq) mir.Error { return nil } -func (s *privSrv) DeleteCommentReply(req *web.DeleteCommentReplyReq) mir.Error { +func (s *privSrv) DeleteCommentReply(c context.Context, req *web.DeleteCommentReplyReq) mir.Error { reply, err := s.Ds.GetCommentReplyByID(req.ID) if err != nil { logrus.Errorf("Ds.GetCommentReplyByID err: %s", err) @@ -390,7 +391,7 @@ func (s *privSrv) DeleteCommentReply(req *web.DeleteCommentReplyReq) mir.Error { return nil } -func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (_ *web.CreateCommentReplyResp, xerr mir.Error) { +func (s *privSrv) CreateCommentReply(c context.Context, req *web.CreateCommentReplyReq) (_ *web.CreateCommentReplyResp, xerr mir.Error) { var ( post *ms.Post comment *ms.Comment @@ -426,8 +427,7 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (_ *web.Cre s.PushPostToSearch(post) // 创建用户消息提醒 - ctx := req.Context() - commentMaster, err := s.Ds.GetUserByID(ctx, comment.UserID) + commentMaster, err := s.Ds.GetUserByID(c, comment.UserID) if err == nil && commentMaster.ID != req.Uid { onCreateMessageEvent(&ms.Message{ SenderUserID: req.Uid, @@ -439,7 +439,7 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (_ *web.Cre ReplyID: reply.ID, }) } - postMaster, err := s.Ds.GetUserByID(ctx, post.UserID) + postMaster, err := s.Ds.GetUserByID(c, post.UserID) if err == nil && postMaster.ID != req.Uid && commentMaster.ID != postMaster.ID { onCreateMessageEvent(&ms.Message{ SenderUserID: req.Uid, @@ -452,7 +452,7 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (_ *web.Cre }) } if atUserID > 0 { - user, err := s.Ds.GetUserByID(ctx, atUserID) + user, err := s.Ds.GetUserByID(c, atUserID) if err == nil && user.ID != req.Uid && commentMaster.ID != user.ID && postMaster.ID != user.ID { // 创建消息提醒 onCreateMessageEvent(&ms.Message{ @@ -471,7 +471,7 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (_ *web.Cre return (*web.CreateCommentReplyResp)(reply), nil } -func (s *privSrv) DeleteComment(req *web.DeleteCommentReq) mir.Error { +func (s *privSrv) DeleteComment(c context.Context, req *web.DeleteCommentReq) mir.Error { comment, err := s.Ds.GetCommentByID(req.ID) if err != nil { logrus.Errorf("Ds.GetCommentByID err: %v\n", err) @@ -500,7 +500,7 @@ func (s *privSrv) DeleteComment(req *web.DeleteCommentReq) mir.Error { return nil } -func (s *privSrv) HighlightComment(req *web.HighlightCommentReq) (*web.HighlightCommentResp, mir.Error) { +func (s *privSrv) HighlightComment(c context.Context, req *web.HighlightCommentReq) (*web.HighlightCommentResp, mir.Error) { status, err := s.Ds.HighlightComment(req.Uid, req.CommentId) if err == cs.ErrNoPermission { return nil, web.ErrNoPermission @@ -516,7 +516,7 @@ func (s *privSrv) HighlightComment(req *web.HighlightCommentReq) (*web.Highlight }, nil } -func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateCommentResp, xerr mir.Error) { +func (s *privSrv) CreateComment(c context.Context, req *web.CreateCommentReq) (_ *web.CreateCommentResp, xerr mir.Error) { var ( mediaContents []string err error @@ -578,7 +578,7 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment s.PushPostToSearch(post) // 创建用户消息提醒 - postMaster, err := s.Ds.GetUserByID(req.Context(), post.UserID) + postMaster, err := s.Ds.GetUserByID(c, post.UserID) if err == nil && postMaster.ID != req.Uid { onCreateMessageEvent(&ms.Message{ SenderUserID: req.Uid, @@ -610,7 +610,7 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment return (*web.CreateCommentResp)(comment), nil } -func (s *privSrv) CollectionTweet(req *web.CollectionTweetReq) (*web.CollectionTweetResp, mir.Error) { +func (s *privSrv) CollectionTweet(c context.Context, req *web.CollectionTweetReq) (*web.CollectionTweetResp, mir.Error) { status := false collection, err := s.Ds.GetUserPostCollection(req.ID, req.Uid) if err != nil { @@ -630,7 +630,7 @@ func (s *privSrv) CollectionTweet(req *web.CollectionTweetReq) (*web.CollectionT }, nil } -func (s *privSrv) StarTweet(req *web.StarTweetReq) (*web.StarTweetResp, mir.Error) { +func (s *privSrv) StarTweet(c context.Context, req *web.StarTweetReq) (*web.StarTweetResp, mir.Error) { status := false star, err := s.Ds.GetUserPostStar(req.ID, req.Uid) if err != nil { @@ -650,7 +650,7 @@ func (s *privSrv) StarTweet(req *web.StarTweetReq) (*web.StarTweetResp, mir.Erro }, nil } -func (s *privSrv) VisibleTweet(req *web.VisibleTweetReq) (*web.VisibleTweetResp, mir.Error) { +func (s *privSrv) VisibleTweet(c context.Context, req *web.VisibleTweetReq) (*web.VisibleTweetResp, mir.Error) { if req.Visibility >= web.TweetVisitInvalid { return nil, xerror.InvalidParams } @@ -675,7 +675,7 @@ func (s *privSrv) VisibleTweet(req *web.VisibleTweetReq) (*web.VisibleTweetResp, }, nil } -func (s *privSrv) StickTweet(req *web.StickTweetReq) (*web.StickTweetResp, mir.Error) { +func (s *privSrv) StickTweet(c context.Context, req *web.StickTweetReq) (*web.StickTweetResp, mir.Error) { post, err := s.Ds.GetPostByID(req.ID) if err != nil { logrus.Errorf("Ds.GetPostByID err: %v\n", err) @@ -693,7 +693,7 @@ func (s *privSrv) StickTweet(req *web.StickTweetReq) (*web.StickTweetResp, mir.E }, nil } -func (s *privSrv) HighlightTweet(req *web.HighlightTweetReq) (res *web.HighlightTweetResp, err mir.Error) { +func (s *privSrv) HighlightTweet(c context.Context, req *web.HighlightTweetReq) (res *web.HighlightTweetResp, err mir.Error) { if status, xerr := s.Ds.HighlightPost(req.User.ID, req.ID); xerr == nil { res = &web.HighlightTweetResp{ HighlightStatus: status, @@ -708,7 +708,7 @@ func (s *privSrv) HighlightTweet(req *web.HighlightTweetReq) (res *web.Highlight return } -func (s *privSrv) LockTweet(req *web.LockTweetReq) (*web.LockTweetResp, mir.Error) { +func (s *privSrv) LockTweet(c context.Context, req *web.LockTweetReq) (*web.LockTweetResp, mir.Error) { post, err := s.Ds.GetPostByID(req.ID) if err != nil { return nil, web.ErrLockPostFailed diff --git a/internal/servants/web/pub.go b/internal/servants/web/pub.go index a16110349..bd356d8cd 100644 --- a/internal/servants/web/pub.go +++ b/internal/servants/web/pub.go @@ -42,7 +42,7 @@ type pubSrv struct { *base.DaoServant } -func (s *pubSrv) SendCaptcha(req *web.SendCaptchaReq) mir.Error { +func (s *pubSrv) SendCaptcha(c context.Context, req *web.SendCaptchaReq) mir.Error { ctx := context.Background() // 验证图片验证码 @@ -66,7 +66,7 @@ func (s *pubSrv) SendCaptcha(req *web.SendCaptchaReq) mir.Error { return nil } -func (s *pubSrv) GetCaptcha() (*web.GetCaptchaResp, mir.Error) { +func (s *pubSrv) GetCaptcha(c context.Context) (*web.GetCaptchaResp, mir.Error) { cap := captcha.New() if err := cap.AddFontFromBytes(assets.ComicBytes); err != nil { logrus.Errorf("cap.AddFontFromBytes err:%s", err) @@ -91,7 +91,7 @@ func (s *pubSrv) GetCaptcha() (*web.GetCaptchaResp, mir.Error) { }, nil } -func (s *pubSrv) Register(req *web.RegisterReq) (*web.RegisterResp, mir.Error) { +func (s *pubSrv) Register(c context.Context, req *web.RegisterReq) (*web.RegisterResp, mir.Error) { if _disallowUserRegister { return nil, web.ErrDisallowUserRegister } @@ -124,7 +124,7 @@ func (s *pubSrv) Register(req *web.RegisterReq) (*web.RegisterResp, mir.Error) { }, nil } -func (s *pubSrv) Login(req *web.LoginReq) (*web.LoginResp, mir.Error) { +func (s *pubSrv) Login(c context.Context, req *web.LoginReq) (*web.LoginResp, mir.Error) { ctx := context.Background() user, err := s.Ds.GetUserByUsername(req.Username) if err != nil { @@ -162,7 +162,7 @@ func (s *pubSrv) Login(req *web.LoginReq) (*web.LoginResp, mir.Error) { }, nil } -func (s *pubSrv) Version() (*web.VersionResp, mir.Error) { +func (s *pubSrv) Version(c context.Context) (*web.VersionResp, mir.Error) { return &web.VersionResp{ BuildInfo: version.ReadBuildInfo(), }, nil diff --git a/internal/servants/web/relax.go b/internal/servants/web/relax.go index 4c230f665..6e0b7e070 100644 --- a/internal/servants/web/relax.go +++ b/internal/servants/web/relax.go @@ -5,6 +5,8 @@ package web import ( + "context" + "github.com/alimy/mir/v4" "github.com/gin-gonic/gin" "github.com/redis/rueidis" @@ -38,7 +40,7 @@ func (s *relaxSrv) Chain() gin.HandlersChain { return gin.HandlersChain{chain.JwtSurely()} } -func (s *relaxSrv) GetUnreadMsgCount(req *web.GetUnreadMsgCountReq) (*web.GetUnreadMsgCountResp, mir.Error) { +func (s *relaxSrv) GetUnreadMsgCount(c context.Context, req *web.GetUnreadMsgCountReq) (*web.GetUnreadMsgCountResp, mir.Error) { if data, xerr := s.wc.GetUnreadMsgCountResp(req.Uid); xerr == nil && len(data) > 0 { // logrus.Debugln("GetUnreadMsgCount get resp from cache") return &web.GetUnreadMsgCountResp{ diff --git a/internal/servants/web/site.go b/internal/servants/web/site.go index ce137fbf6..3ce5938b7 100644 --- a/internal/servants/web/site.go +++ b/internal/servants/web/site.go @@ -5,6 +5,8 @@ package web import ( + "context" + "github.com/alimy/mir/v4" api "github.com/rocboss/paopao-ce/auto/api/v1" "github.com/rocboss/paopao-ce/internal/conf" @@ -22,11 +24,11 @@ type siteSrv struct { *base.BaseServant } -func (*siteSrv) Profile() (*web.SiteProfileResp, mir.Error) { +func (*siteSrv) Profile(c context.Context) (*web.SiteProfileResp, mir.Error) { return conf.WebProfileSetting, nil } -func (*siteSrv) Version() (*web.VersionResp, mir.Error) { +func (*siteSrv) Version(c context.Context) (*web.VersionResp, mir.Error) { return &web.VersionResp{ BuildInfo: version.ReadBuildInfo(), }, nil diff --git a/internal/servants/web/trends.go b/internal/servants/web/trends.go index 581716065..60111335d 100644 --- a/internal/servants/web/trends.go +++ b/internal/servants/web/trends.go @@ -5,6 +5,7 @@ package web import ( + "context" "fmt" "github.com/alimy/mir/v4" @@ -35,7 +36,7 @@ func (s *trendsSrv) Chain() gin.HandlersChain { return gin.HandlersChain{chain.JWT()} } -func (s *trendsSrv) GetIndexTrends(req *web.GetIndexTrendsReq) (res *web.GetIndexTrendsResp, _ mir.Error) { +func (s *trendsSrv) GetIndexTrends(c context.Context, req *web.GetIndexTrendsReq) (res *web.GetIndexTrendsResp, _ mir.Error) { limit, offset := req.PageSize, (req.Page-1)*req.PageSize // 尝试直接从缓存中获取数据 key, ok := "", false diff --git a/mirc/gen.go b/mirc/gen.go index dcd402ac5..f8671d8f6 100644 --- a/mirc/gen.go +++ b/mirc/gen.go @@ -26,6 +26,7 @@ func main() { log.Println("[Mir] generate code start") opts := Options{ UseGin(), + UseRequestContext(), SinkPath("../auto"), WatchCtxDone(true), RunMode(InSerialMode),