diff --git a/internal/handler/achievement/pagingaccomplishedlist.go b/internal/handler/achievement/pagingaccomplishedlist.go index d621a4b..0e10e34 100644 --- a/internal/handler/achievement/pagingaccomplishedlist.go +++ b/internal/handler/achievement/pagingaccomplishedlist.go @@ -16,7 +16,7 @@ const pagingAccomplishedPageSize = 10 func pagingAccomplishedList(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := achievementschema.PagingAccomplishedListReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/album/seriesall.go b/internal/handler/album/seriesall.go index e943982..bbd3ea6 100644 --- a/internal/handler/album/seriesall.go +++ b/internal/handler/album/seriesall.go @@ -12,7 +12,7 @@ import ( func seriesAll(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() var albumID []int err := ss.MainEng.Table("album_series_m").Select("album_series_id").Find(&albumID) diff --git a/internal/handler/announce/checkstate.go b/internal/handler/announce/checkstate.go index 76904b4..9a0fd8a 100644 --- a/internal/handler/announce/checkstate.go +++ b/internal/handler/announce/checkstate.go @@ -13,7 +13,7 @@ import ( func checkState(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(announceschema.CheckStateDataResp{ ResponseData: announceschema.CheckStateData{ diff --git a/internal/handler/api/api.go b/internal/handler/api/api.go index 01d3f15..103cafa 100644 --- a/internal/handler/api/api.go +++ b/internal/handler/api/api.go @@ -41,7 +41,7 @@ import ( func api(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() apiReq := []apischema.ApiReq{} err := honokautils.ParseRequestData(ctx, &apiReq) diff --git a/internal/handler/award/set.go b/internal/handler/award/set.go index ec5e41b..41fe885 100644 --- a/internal/handler/award/set.go +++ b/internal/handler/award/set.go @@ -14,7 +14,7 @@ import ( func set(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() reqData := gjson.Parse(ctx.MustGet("request_data").(string)) pref := usermodel.UserPref{ diff --git a/internal/handler/background/set.go b/internal/handler/background/set.go index 53b6a8f..fe3fa54 100644 --- a/internal/handler/background/set.go +++ b/internal/handler/background/set.go @@ -14,7 +14,7 @@ import ( func set(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() reqData := gjson.Parse(ctx.MustGet("request_data").(string)) pref := usermodel.UserPref{ diff --git a/internal/handler/banner/list.go b/internal/handler/banner/list.go index 397df28..63ce95c 100644 --- a/internal/handler/banner/list.go +++ b/internal/handler/banner/list.go @@ -18,7 +18,7 @@ type bannerResp struct { func list(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() data, err := apibanner.BannerApi("bannerList") if ss.CheckErr(err) { diff --git a/internal/handler/download/additional.go b/internal/handler/download/additional.go index 07f7678..649609d 100644 --- a/internal/handler/download/additional.go +++ b/internal/handler/download/additional.go @@ -15,7 +15,7 @@ import ( func additional(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() downloadReq := downloadschema.AdditionalReq{} err := honokautils.ParseRequestData(ctx, &downloadReq) diff --git a/internal/handler/download/batch.go b/internal/handler/download/batch.go index 9a4b7b7..1bfceca 100644 --- a/internal/handler/download/batch.go +++ b/internal/handler/download/batch.go @@ -16,7 +16,7 @@ import ( func batch(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() downloadReq := downloadschema.BatchReq{} err := honokautils.ParseRequestData(ctx, &downloadReq) diff --git a/internal/handler/download/event.go b/internal/handler/download/event.go index c1e4fc5..d9f0858 100644 --- a/internal/handler/download/event.go +++ b/internal/handler/download/event.go @@ -12,7 +12,7 @@ import ( func event(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(downloadschema.EventResp{ ResponseData: []any{}, diff --git a/internal/handler/download/geturl.go b/internal/handler/download/geturl.go index ee227e1..3289a28 100644 --- a/internal/handler/download/geturl.go +++ b/internal/handler/download/geturl.go @@ -16,7 +16,7 @@ import ( func getUrl(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() downloadReq := downloadschema.UrlReq{} err := honokautils.ParseRequestData(ctx, &downloadReq) diff --git a/internal/handler/download/update.go b/internal/handler/download/update.go index af200ac..fbaea46 100644 --- a/internal/handler/download/update.go +++ b/internal/handler/download/update.go @@ -19,7 +19,7 @@ const overrideServerConfigFileName = "99_0_115.zip" func update(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() downloadReq := downloadschema.UpdateReq{} err := honokautils.ParseRequestData(ctx, &downloadReq) diff --git a/internal/handler/event/list.go b/internal/handler/event/list.go index 4c7f1f8..9363637 100644 --- a/internal/handler/event/list.go +++ b/internal/handler/event/list.go @@ -13,7 +13,7 @@ import ( func list(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() targets := []eventschema.TargetList{} for i := range 6 { diff --git a/internal/handler/eventscenario/startup.go b/internal/handler/eventscenario/startup.go index 1f4ee55..4290485 100644 --- a/internal/handler/eventscenario/startup.go +++ b/internal/handler/eventscenario/startup.go @@ -13,7 +13,7 @@ import ( func startup(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() startReq := eventscenarioschema.StartUpReq{} err := honokautils.ParseRequestData(ctx, &startReq) diff --git a/internal/handler/friend/expel.go b/internal/handler/friend/expel.go index 060eb08..689a026 100644 --- a/internal/handler/friend/expel.go +++ b/internal/handler/friend/expel.go @@ -14,7 +14,7 @@ import ( func expel(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := friendschema.UserIDReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/friend/list.go b/internal/handler/friend/list.go index f0deb6e..ad80d0f 100644 --- a/internal/handler/friend/list.go +++ b/internal/handler/friend/list.go @@ -33,7 +33,7 @@ type friendListRow struct { func list(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() listReq := friendschema.ListReq{} err := honokautils.ParseRequestData(ctx, &listReq) diff --git a/internal/handler/friend/request.go b/internal/handler/friend/request.go index 5d495a4..9edf870 100644 --- a/internal/handler/friend/request.go +++ b/internal/handler/friend/request.go @@ -15,7 +15,7 @@ import ( func request(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := friendschema.UserIDReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/friend/requestcancel.go b/internal/handler/friend/requestcancel.go index c1b40ef..e066fab 100644 --- a/internal/handler/friend/requestcancel.go +++ b/internal/handler/friend/requestcancel.go @@ -14,7 +14,7 @@ import ( func requestCancel(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := friendschema.UserIDReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/friend/response.go b/internal/handler/friend/response.go index 2ad3207..110f101 100644 --- a/internal/handler/friend/response.go +++ b/internal/handler/friend/response.go @@ -15,7 +15,7 @@ import ( func response(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := friendschema.ResponseReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/friend/search.go b/internal/handler/friend/search.go index 8c0ce38..bb5fadf 100644 --- a/internal/handler/friend/search.go +++ b/internal/handler/friend/search.go @@ -30,7 +30,7 @@ type friendSearchRow struct { func search(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := friendschema.SearchReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/gdpr/get.go b/internal/handler/gdpr/get.go index 540eb77..ff5b46b 100644 --- a/internal/handler/gdpr/get.go +++ b/internal/handler/gdpr/get.go @@ -13,7 +13,7 @@ import ( func get(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(gdprschema.GetResp{ ResponseData: gdprschema.GetData{ diff --git a/internal/handler/ghome/account/active.go b/internal/handler/ghome/account/active.go index 10d181c..865ddb9 100644 --- a/internal/handler/ghome/account/active.go +++ b/internal/handler/ghome/account/active.go @@ -10,7 +10,7 @@ import ( func active(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(ghomeschema.ActiveResp{ Code: 0, diff --git a/internal/handler/ghome/account/initialize.go b/internal/handler/ghome/account/initialize.go index 235aff1..ba73074 100644 --- a/internal/handler/ghome/account/initialize.go +++ b/internal/handler/ghome/account/initialize.go @@ -14,7 +14,7 @@ import ( func initialize(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() initData := ghomeschema.InitializeData{ BrandLogo: "http://gskd.sdo.com/ghome/ztc/logo/og/logo_xhdpi.png", diff --git a/internal/handler/ghome/account/login.go b/internal/handler/ghome/account/login.go index 6d70375..c391b23 100644 --- a/internal/handler/ghome/account/login.go +++ b/internal/handler/ghome/account/login.go @@ -34,7 +34,7 @@ const ( func login(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() data, err := ctx.GetRawData() if ss.CheckErr(err) { diff --git a/internal/handler/ghome/account/loginauto.go b/internal/handler/ghome/account/loginauto.go index ded4ab8..b7e4085 100644 --- a/internal/handler/ghome/account/loginauto.go +++ b/internal/handler/ghome/account/loginauto.go @@ -16,7 +16,7 @@ import ( func loginAuto(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() data, err := ctx.GetRawData() if ss.CheckErr(err) { diff --git a/internal/handler/ghome/account/reportrole.go b/internal/handler/ghome/account/reportrole.go index 0669c1e..37c0c18 100644 --- a/internal/handler/ghome/account/reportrole.go +++ b/internal/handler/ghome/account/reportrole.go @@ -12,7 +12,7 @@ import ( func reportRole(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() randKey, err := ss.Get3DESRandKey() if ss.CheckErr(err) { diff --git a/internal/handler/ghome/basic/getcode.go b/internal/handler/ghome/basic/getcode.go index d6dd1a8..2743946 100644 --- a/internal/handler/ghome/basic/getcode.go +++ b/internal/handler/ghome/basic/getcode.go @@ -11,7 +11,7 @@ import ( func getCode(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() codeArray := `{"codeArray":[{"btntext":"好的","code":"-10264022","msg_from":2,"text":"","title":"短信验证码被阻止","type":1},{"btntext":"","code":"-10869623","msg_from":2,"text":"","title":"网络连接失败,无法一键登录","type":2},{"btntext":"","code":"10298300","msg_from":2,"text":"","title":"","type":3},{"btntext":"","code":"10298311","msg_from":2,"text":"","title":"","type":3},{"btntext":"","code":"10298312","msg_from":2,"text":"","title":"","type":3},{"btntext":"","code":"10298313","msg_from":2,"text":"","title":"","type":1},{"btntext":"","code":"10298321","msg_from":2,"text":"","title":"","type":3},{"btntext":"","code":"10298322","msg_from":2,"text":"","title":"","type":3}],"codeVersion":"1.0.5"}` getCodeData := map[string]any{} diff --git a/internal/handler/ghome/basic/getproductlist.go b/internal/handler/ghome/basic/getproductlist.go index ccfddee..d57731b 100644 --- a/internal/handler/ghome/basic/getproductlist.go +++ b/internal/handler/ghome/basic/getproductlist.go @@ -10,7 +10,7 @@ import ( func getProductList(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() getProductListData := ghomeschema.GetProductListData{ Message: []string{}, diff --git a/internal/handler/ghome/basic/handshake.go b/internal/handler/ghome/basic/handshake.go index 7835ce1..ef5781e 100644 --- a/internal/handler/ghome/basic/handshake.go +++ b/internal/handler/ghome/basic/handshake.go @@ -18,7 +18,7 @@ import ( func handshake(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() data, err := ctx.GetRawData() if ss.CheckErr(err) { diff --git a/internal/handler/ghome/basic/loginarea.go b/internal/handler/ghome/basic/loginarea.go index 7ee8ddf..a60a620 100644 --- a/internal/handler/ghome/basic/loginarea.go +++ b/internal/handler/ghome/basic/loginarea.go @@ -10,7 +10,7 @@ import ( func loginArea(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(ghomeschema.LoginAreaResp{ Code: 0, diff --git a/internal/handler/ghome/basic/publickey.go b/internal/handler/ghome/basic/publickey.go index 9d3bbfa..6c300a8 100644 --- a/internal/handler/ghome/basic/publickey.go +++ b/internal/handler/ghome/basic/publickey.go @@ -14,7 +14,7 @@ import ( func publicKey(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() publicKeyCode := 0 publicKeyMsg := "ok" diff --git a/internal/handler/ghome/guest/status.go b/internal/handler/ghome/guest/status.go index dac27c4..1987429 100644 --- a/internal/handler/ghome/guest/status.go +++ b/internal/handler/ghome/guest/status.go @@ -10,7 +10,7 @@ import ( func status(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(ghomeschema.GuestStatusResp{ Code: 0, diff --git a/internal/handler/ghome/misc/agreement.go b/internal/handler/ghome/misc/agreement.go index c18c54f..72fd387 100644 --- a/internal/handler/ghome/misc/agreement.go +++ b/internal/handler/ghome/misc/agreement.go @@ -10,7 +10,7 @@ import ( func agreement(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(ghomeschema.AgreementResp{ ReturnCode: 0, diff --git a/internal/handler/ghome/misc/integration.go b/internal/handler/ghome/misc/integration.go index 6ba8991..77f99d1 100644 --- a/internal/handler/ghome/misc/integration.go +++ b/internal/handler/ghome/misc/integration.go @@ -10,7 +10,7 @@ import ( func appReport(ctx *gin.Context) { ss := session.Attach(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(ghomeschema.AppReportResp{ Code: 0, diff --git a/internal/handler/greet/delete.go b/internal/handler/greet/delete.go index 32481c8..c66a33c 100644 --- a/internal/handler/greet/delete.go +++ b/internal/handler/greet/delete.go @@ -16,7 +16,7 @@ import ( func deleteMail(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := greetschema.DeleteReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/greet/user.go b/internal/handler/greet/user.go index d72a02a..c044523 100644 --- a/internal/handler/greet/user.go +++ b/internal/handler/greet/user.go @@ -18,7 +18,7 @@ import ( func user(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := greetschema.UserReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/lbonus/execute.go b/internal/handler/lbonus/execute.go index bba97c0..6a0f5c6 100644 --- a/internal/handler/lbonus/execute.go +++ b/internal/handler/lbonus/execute.go @@ -13,7 +13,7 @@ import ( func execute(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() weeks := map[string]int{ "Monday": 1, diff --git a/internal/handler/live/continue.go b/internal/handler/live/continue.go index 61dfb2f..7fc7484 100644 --- a/internal/handler/live/continue.go +++ b/internal/handler/live/continue.go @@ -13,7 +13,7 @@ import ( func continuee(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(BuildContinueResp(ss)) } diff --git a/internal/handler/live/partylist.go b/internal/handler/live/partylist.go index 7506f21..4f3fbf4 100644 --- a/internal/handler/live/partylist.go +++ b/internal/handler/live/partylist.go @@ -14,7 +14,7 @@ import ( func partyList(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() partyListData, err := BuildPartyListData(ss) if ss.CheckErr(err) { return diff --git a/internal/handler/live/play.go b/internal/handler/live/play.go index 59c6762..80ca577 100644 --- a/internal/handler/live/play.go +++ b/internal/handler/live/play.go @@ -17,7 +17,7 @@ import ( func play(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() playReq := liveschema.PlayReq{} err := honokautils.ParseRequestData(ctx, &playReq) diff --git a/internal/handler/live/precisescore.go b/internal/handler/live/precisescore.go index 5e1a550..a419ca0 100644 --- a/internal/handler/live/precisescore.go +++ b/internal/handler/live/precisescore.go @@ -18,7 +18,7 @@ import ( func preciseScore(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() playScoreReq := liveschema.PlayScoreReq{} err := honokautils.ParseRequestData(ctx, &playScoreReq) diff --git a/internal/handler/login/authkey.go b/internal/handler/login/authkey.go index 6a54ef8..66da8b4 100644 --- a/internal/handler/login/authkey.go +++ b/internal/handler/login/authkey.go @@ -18,7 +18,7 @@ import ( func authKey(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() reqData := gjson.Parse(ctx.MustGet("request_data").(string)) dummyToken, err := base64.StdEncoding.DecodeString(reqData.Get("dummy_token").String()) diff --git a/internal/handler/login/login.go b/internal/handler/login/login.go index d6feccb..55f6e18 100644 --- a/internal/handler/login/login.go +++ b/internal/handler/login/login.go @@ -19,7 +19,7 @@ import ( func login(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() has, authKeyData, err := ss.GetAuthKey(ctx.MustGet("token").(string)) if ss.CheckErr(err) { diff --git a/internal/handler/multiunit/scenariostartup.go b/internal/handler/multiunit/scenariostartup.go index 0a80b22..bbc8345 100644 --- a/internal/handler/multiunit/scenariostartup.go +++ b/internal/handler/multiunit/scenariostartup.go @@ -14,7 +14,7 @@ import ( func scenarioStartup(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() startReq := multiunitschema.ScenarioStartUpReq{} err := honokautils.ParseRequestData(ctx, &startReq) diff --git a/internal/handler/museum/info.go b/internal/handler/museum/info.go index 9bd19f0..92ecce3 100644 --- a/internal/handler/museum/info.go +++ b/internal/handler/museum/info.go @@ -13,7 +13,7 @@ import ( func info(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() var contents []struct { MuseumContentsId int `xorm:"museum_contents_id"` diff --git a/internal/handler/notice/friendgreeting.go b/internal/handler/notice/friendgreeting.go index 89a1591..1668f84 100644 --- a/internal/handler/notice/friendgreeting.go +++ b/internal/handler/notice/friendgreeting.go @@ -15,7 +15,7 @@ import ( func friendGreeting(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := noticeschema.GreetingNoticeReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/notice/friendvariety.go b/internal/handler/notice/friendvariety.go index a5aedd4..8e68078 100644 --- a/internal/handler/notice/friendvariety.go +++ b/internal/handler/notice/friendvariety.go @@ -13,7 +13,7 @@ import ( func friendVariety(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(noticeschema.FriendVarietyResp{ ResponseData: noticeschema.FriendVarietyData{ diff --git a/internal/handler/notice/usergreetinghistory.go b/internal/handler/notice/usergreetinghistory.go index 0416fde..94912b2 100644 --- a/internal/handler/notice/usergreetinghistory.go +++ b/internal/handler/notice/usergreetinghistory.go @@ -15,7 +15,7 @@ import ( func userGreetingHistory(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := noticeschema.GreetingNoticeReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/payment/productlist.go b/internal/handler/payment/productlist.go index 2d8bcc4..8609564 100644 --- a/internal/handler/payment/productlist.go +++ b/internal/handler/payment/productlist.go @@ -14,7 +14,7 @@ import ( func productList(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() prodResp := paymentschema.ProductListResp{ ResponseData: paymentschema.ProductListData{ diff --git a/internal/handler/personalnotice/get.go b/internal/handler/personalnotice/get.go index f2e9baf..a5a5493 100644 --- a/internal/handler/personalnotice/get.go +++ b/internal/handler/personalnotice/get.go @@ -13,7 +13,7 @@ import ( func get(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() noticeResp := personalnoticeschema.GetResp{ ResponseData: personalnoticeschema.GetData{ diff --git a/internal/handler/profile/register.go b/internal/handler/profile/register.go index 72016b2..9875c2e 100644 --- a/internal/handler/profile/register.go +++ b/internal/handler/profile/register.go @@ -14,7 +14,7 @@ import ( func register(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := gjson.Parse(ctx.PostForm("request_data")) pref := usermodel.UserPref{ diff --git a/internal/handler/ranking/live.go b/internal/handler/ranking/live.go index d909272..d562ca9 100644 --- a/internal/handler/ranking/live.go +++ b/internal/handler/ranking/live.go @@ -28,7 +28,7 @@ type liveRankingRow struct { func live(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := rankingschema.LiveReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/reward/history.go b/internal/handler/reward/history.go index 81eb8f8..3b62c5c 100644 --- a/internal/handler/reward/history.go +++ b/internal/handler/reward/history.go @@ -12,7 +12,7 @@ import ( func history(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(rewardschema.HistoryResp{ ResponseData: rewardschema.HistoryData{ diff --git a/internal/handler/reward/list.go b/internal/handler/reward/list.go index 8c99e61..3b325a8 100644 --- a/internal/handler/reward/list.go +++ b/internal/handler/reward/list.go @@ -12,7 +12,7 @@ import ( func list(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(rewardschema.ListResp{ ResponseData: rewardschema.ListData{ diff --git a/internal/handler/reward/sellunit.go b/internal/handler/reward/sellunit.go index f277df4..e441caf 100644 --- a/internal/handler/reward/sellunit.go +++ b/internal/handler/reward/sellunit.go @@ -13,7 +13,7 @@ import ( func sellUnit(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(rewardschema.SellUnitResp{ ResponseData: commonschema.ErrorData{ diff --git a/internal/handler/rlive/continue.go b/internal/handler/rlive/continue.go index cd1649c..d7ae97d 100644 --- a/internal/handler/rlive/continue.go +++ b/internal/handler/rlive/continue.go @@ -14,7 +14,7 @@ import ( func continuee(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := rliveschema.TokenReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/rlive/lot.go b/internal/handler/rlive/lot.go index b728b03..a6c42c5 100644 --- a/internal/handler/rlive/lot.go +++ b/internal/handler/rlive/lot.go @@ -31,7 +31,7 @@ type randomLiveCandidateRow struct { func lot(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := rliveschema.LotReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/rlive/play.go b/internal/handler/rlive/play.go index bcd0996..4b8c205 100644 --- a/internal/handler/rlive/play.go +++ b/internal/handler/rlive/play.go @@ -14,7 +14,7 @@ import ( func play(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := rliveschema.PlayReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/scenario/startup.go b/internal/handler/scenario/startup.go index f44dc22..2474c61 100644 --- a/internal/handler/scenario/startup.go +++ b/internal/handler/scenario/startup.go @@ -14,7 +14,7 @@ import ( func startup(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() startReq := scenarioschema.StartUpReq{} err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &startReq) diff --git a/internal/handler/secretbox/multi.go b/internal/handler/secretbox/multi.go index f9b7275..f78d241 100644 --- a/internal/handler/secretbox/multi.go +++ b/internal/handler/secretbox/multi.go @@ -13,7 +13,7 @@ import ( func multi(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() multiReq := secretboxschema.MultiReq{} err := honokautils.ParseRequestData(ctx, &multiReq) diff --git a/internal/handler/secretbox/pon.go b/internal/handler/secretbox/pon.go index 292f119..c8a8bdd 100644 --- a/internal/handler/secretbox/pon.go +++ b/internal/handler/secretbox/pon.go @@ -18,7 +18,7 @@ import ( func pon(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ponReq := secretboxschema.PonReq{} err := honokautils.ParseRequestData(ctx, &ponReq) diff --git a/internal/handler/secretbox/showdetail.go b/internal/handler/secretbox/showdetail.go index 6dfd87a..85c5255 100644 --- a/internal/handler/secretbox/showdetail.go +++ b/internal/handler/secretbox/showdetail.go @@ -14,7 +14,7 @@ import ( func showDetail(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() showDetailReq := secretboxschema.ShowDetailReq{} err := honokautils.ParseRequestData(ctx, &showDetailReq) diff --git a/internal/handler/subscenario/startup.go b/internal/handler/subscenario/startup.go index b75a066..4f462b1 100644 --- a/internal/handler/subscenario/startup.go +++ b/internal/handler/subscenario/startup.go @@ -14,7 +14,7 @@ import ( func startup(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() startReq := subscenarioschema.StartUpReq{} err := honokautils.ParseRequestData(ctx, &startReq) diff --git a/internal/handler/tos/check.go b/internal/handler/tos/check.go index 9d12baf..896019b 100644 --- a/internal/handler/tos/check.go +++ b/internal/handler/tos/check.go @@ -13,7 +13,7 @@ import ( func check(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(tosschema.CheckResp{ ResponseData: tosschema.CheckData{ diff --git a/internal/handler/unit/deck.go b/internal/handler/unit/deck.go index 6b217d7..2032ec4 100644 --- a/internal/handler/unit/deck.go +++ b/internal/handler/unit/deck.go @@ -17,7 +17,7 @@ import ( func deck(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() deckReq := unitschema.DeckReq{} err := honokautils.ParseRequestData(ctx, &deckReq) diff --git a/internal/handler/unit/deckname.go b/internal/handler/unit/deckname.go index 95851b6..a2a82e8 100644 --- a/internal/handler/unit/deckname.go +++ b/internal/handler/unit/deckname.go @@ -14,7 +14,7 @@ import ( func deckName(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() deckReq := unitschema.DeckNameReq{} err := honokautils.ParseRequestData(ctx, &deckReq) diff --git a/internal/handler/unit/favorite.go b/internal/handler/unit/favorite.go index 17933e1..81c70f4 100644 --- a/internal/handler/unit/favorite.go +++ b/internal/handler/unit/favorite.go @@ -14,7 +14,7 @@ import ( func favorite(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() var req unitschema.FavoriteReq err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/unit/favoriteaccessory.go b/internal/handler/unit/favoriteaccessory.go index 07c0c35..4dc781b 100644 --- a/internal/handler/unit/favoriteaccessory.go +++ b/internal/handler/unit/favoriteaccessory.go @@ -18,7 +18,7 @@ type SetResp struct { func favoriteAccessory(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() fmt.Println(ctx.MustGet("request_data").(string)) diff --git a/internal/handler/unit/removableskillequipment.go b/internal/handler/unit/removableskillequipment.go index 27fc50c..415abdb 100644 --- a/internal/handler/unit/removableskillequipment.go +++ b/internal/handler/unit/removableskillequipment.go @@ -13,7 +13,7 @@ import ( func removableSkillEquipment(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := unitschema.RemovableSkillEquipmentReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/unit/sale.go b/internal/handler/unit/sale.go index cc98c1d..1d2f710 100644 --- a/internal/handler/unit/sale.go +++ b/internal/handler/unit/sale.go @@ -15,7 +15,7 @@ import ( func sale(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := unitschema.SaleReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/unit/setdisplayrank.go b/internal/handler/unit/setdisplayrank.go index 53fccb6..76b748c 100644 --- a/internal/handler/unit/setdisplayrank.go +++ b/internal/handler/unit/setdisplayrank.go @@ -14,7 +14,7 @@ import ( func setDisplayRank(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() var req unitschema.SetDisplayRankReq err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/unit/wearaccessory.go b/internal/handler/unit/wearaccessory.go index 8796231..1dcb9d7 100644 --- a/internal/handler/unit/wearaccessory.go +++ b/internal/handler/unit/wearaccessory.go @@ -15,7 +15,7 @@ import ( func wearAccessory(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := unitschema.WearAccessoryReq{} err := honokautils.ParseRequestData(ctx, &req) diff --git a/internal/handler/user/changename.go b/internal/handler/user/changename.go index d5f00e3..218dabd 100644 --- a/internal/handler/user/changename.go +++ b/internal/handler/user/changename.go @@ -15,7 +15,7 @@ import ( func changeName(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := gjson.Parse(ctx.MustGet("request_data").(string)) var oldName string diff --git a/internal/handler/user/changenavi.go b/internal/handler/user/changenavi.go index 1b46748..bb30cde 100644 --- a/internal/handler/user/changenavi.go +++ b/internal/handler/user/changenavi.go @@ -14,7 +14,7 @@ import ( func changeNavi(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() req := gjson.Parse(ctx.MustGet("request_data").(string)) pref := usermodel.UserPref{ diff --git a/internal/handler/user/setnotificationtoken.go b/internal/handler/user/setnotificationtoken.go index 2a03d54..378a355 100644 --- a/internal/handler/user/setnotificationtoken.go +++ b/internal/handler/user/setnotificationtoken.go @@ -12,7 +12,7 @@ import ( func setNotificationToken(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() ss.Respond(userschema.SetNotificationTokenResp{ ResponseData: []any{}, diff --git a/internal/handler/user/userinfo.go b/internal/handler/user/userinfo.go index 2b9950c..cefb9f7 100644 --- a/internal/handler/user/userinfo.go +++ b/internal/handler/user/userinfo.go @@ -13,7 +13,7 @@ import ( func userInfo(ctx *gin.Context) { ss := session.Get(ctx) - defer ss.Finalize() + defer ss.FinalizeOrRollback() userResp := userschema.UserInfoResp{ ResponseData: userschema.UserInfoData{ diff --git a/internal/middleware/common.go b/internal/middleware/common.go index abaa1bd..048fe2c 100644 --- a/internal/middleware/common.go +++ b/internal/middleware/common.go @@ -29,10 +29,15 @@ func Common(ctx *gin.Context) { ss := session.Attach(ctx) ctx.Set("session", ss) + defer ss.FinalizeOrRollback() - if ctx.Request.URL.Path != "/login/authkey" && ctx.Request.URL.Path != "/login/login" { + if ctx.IsAborted() { + return + } + + if !honokautils.IsMainLoginEndpoint(ctx.Request.URL.Path) { if ss.UserPref.ForceRelogin { - honokautils.AbortMaintenanceJSON(ctx, http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.String())) + ss.AbortWithStatus(http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.Path)) return } } @@ -40,7 +45,7 @@ func Common(ctx *gin.Context) { authorize := ctx.GetHeader("Authorize") params, err := url.ParseQuery(authorize) if err != nil { - honokautils.AbortMaintenanceJSON(ctx, http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.String())) + ss.AbortWithStatus(http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.Path)) return } diff --git a/internal/middleware/recovery.go b/internal/middleware/recovery.go index 5de12a5..141c17e 100644 --- a/internal/middleware/recovery.go +++ b/internal/middleware/recovery.go @@ -21,18 +21,18 @@ func Recovery() gin.HandlerFunc { stack := debug.Stack() log.Printf("panic serving %s %s: %v\n%s", ctx.Request.Method, ctx.Request.URL.String(), recovered, stack) + if value, ok := ctx.Get("session"); ok { + if ss, ok := value.(*session.Session); ok { + ss.Rollback() + } + } + if !honokautils.IsMainPHPRequest(ctx.Request.URL.Path) { ctx.AbortWithStatus(http.StatusInternalServerError) return } - content := honokautils.NewPanicContent(recovered, stack) - if value, ok := ctx.Get("session"); ok { - value.(*session.Session).AbortWithStatus(http.StatusInternalServerError, content) - return - } - - honokautils.AbortMaintenanceJSON(ctx, http.StatusInternalServerError, content) + honokautils.AbortMaintenanceJSON(ctx, http.StatusInternalServerError, honokautils.NewPanicContent()) }() ctx.Next() diff --git a/internal/router/router.go b/internal/router/router.go index 42baca0..dbc7cea 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -116,7 +116,7 @@ func SifRouter(r *gin.Engine) { return } - honokautils.AbortMaintenanceJSON(ctx, http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.String())) + honokautils.AbortMaintenanceJSON(ctx, http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.Path)) } r.NoRoute(notFoundHandler) r.NoMethod(notFoundHandler) diff --git a/internal/session/session.go b/internal/session/session.go index 0b9b129..5de739a 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -90,7 +90,7 @@ func (ss *Session) Finalize() { if err := ss.UserEng.Commit(); err != nil { log.Println(err.Error()) ss.closeAllSessions(false) - ss.respondError(http.StatusInternalServerError, honokautils.NewInternalErrorContent(err)) + ss.respondError(http.StatusInternalServerError, honokautils.NewInternalErrorContent()) return } @@ -106,7 +106,7 @@ func (ss *Session) Abort(err error) { msg := ss.formatAbortMessage(err) log.Println(msg) - ss.abortWithContent(http.StatusInternalServerError, honokautils.NewErrorContent("SessionAbort", msg)) + ss.abortWithContent(http.StatusInternalServerError, honokautils.NewInternalErrorContent()) } func (ss *Session) AbortWithStatus(status int, content any) { @@ -116,6 +116,25 @@ func (ss *Session) AbortWithStatus(status int, content any) { ss.abortWithContent(status, content) } +// FinalizeOrRollback commits successful requests and rolls back before a panic reaches recovery. +func (ss *Session) FinalizeOrRollback() { + defer func() { + if recovered := recover(); recovered != nil { + ss.Rollback() + panic(recovered) + } + }() + ss.Finalize() +} + +func (ss *Session) Rollback() { + if ss.done { + return + } + ss.done = true + ss.closeAllSessions(true) +} + func (ss *Session) formatAbortMessage(err error) string { skip := 2 if pc, _, _, ok := runtime.Caller(2); ok { diff --git a/internal/utils/error.go b/internal/utils/error.go index 7f7192d..cd1749b 100644 --- a/internal/utils/error.go +++ b/internal/utils/error.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "net/http" - "reflect" "strconv" "strings" @@ -48,16 +47,19 @@ func IsUnimplementedError(err error) bool { const maintenanceHeader = "Maintenance" type ErrorContent struct { - Detail string `json:"detail,omitempty"` - Exception string `json:"exception,omitempty"` - Message string `json:"message,omitempty"` - Traceback []string `json:"traceback,omitempty"` + Detail string `json:"detail,omitempty"` + Exception string `json:"exception,omitempty"` + Message string `json:"message,omitempty"` } func IsMainPHPRequest(path string) bool { return path == "/main.php" || strings.HasPrefix(path, "/main.php/") } +func IsMainLoginEndpoint(path string) bool { + return path == "/main.php/login/authkey" || path == "/main.php/login/login" +} + func WriteMaintenanceJSON(setHeader func(string, string), writeJSON func(int, any), status int, content any) { setHeader("Content-Type", "application/json; charset=utf-8") setHeader("status_code", strconv.Itoa(status)) @@ -80,46 +82,13 @@ func NewNotFoundContent(path string) ErrorContent { return NewDetailContent(fmt.Sprintf("Endpoint not found: %s", path)) } -func NewInternalErrorContent(err error) ErrorContent { +func NewInternalErrorContent() ErrorContent { return ErrorContent{ - Exception: exceptionName(err), - Message: err.Error(), + Exception: "InternalServerError", + Message: http.StatusText(http.StatusInternalServerError), } } -func NewErrorContent(exception, message string) ErrorContent { - return ErrorContent{ - Exception: exception, - Message: message, - } -} - -func NewPanicContent(recovered any, stack []byte) ErrorContent { - return ErrorContent{ - Exception: "panic", - Message: fmt.Sprint(recovered), - Traceback: splitLines(stack), - } -} - -func exceptionName(err error) string { - if err == nil { - return http.StatusText(http.StatusInternalServerError) - } - - typ := reflect.TypeOf(err) - if typ.Kind() == reflect.Pointer { - typ = typ.Elem() - } - if name := typ.Name(); name != "" { - return name - } - return typ.String() -} - -func splitLines(stack []byte) []string { - if len(stack) == 0 { - return nil - } - return strings.Split(strings.TrimSpace(string(stack)), "\n") +func NewPanicContent() ErrorContent { + return NewInternalErrorContent() } diff --git a/internal/utils/error_test.go b/internal/utils/error_test.go new file mode 100644 index 0000000..300e6d0 --- /dev/null +++ b/internal/utils/error_test.go @@ -0,0 +1,39 @@ +package honokautils + +import ( + "net/http" + "testing" +) + +func TestInternalErrorContentIsSanitized(t *testing.T) { + content := NewInternalErrorContent() + + if content.Exception != "InternalServerError" { + t.Fatalf("unexpected exception: %q", content.Exception) + } + if content.Message != http.StatusText(http.StatusInternalServerError) { + t.Fatalf("unexpected message: %q", content.Message) + } +} + +func TestPanicContentIsSanitized(t *testing.T) { + content := NewPanicContent() + + if content != NewInternalErrorContent() { + t.Fatalf("panic content exposes a distinct internal detail: %#v", content) + } +} + +func TestIsMainLoginEndpoint(t *testing.T) { + for _, path := range []string{"/main.php/login/authkey", "/main.php/login/login"} { + if !IsMainLoginEndpoint(path) { + t.Fatalf("expected %q to be a main.php login endpoint", path) + } + } + + for _, path := range []string{"/login/authkey", "/main.php/user/userInfo"} { + if IsMainLoginEndpoint(path) { + t.Fatalf("expected %q not to be a main.php login endpoint", path) + } + } +}