diff --git a/config/config.go b/config/config.go index 4985b59..5b009dd 100644 --- a/config/config.go +++ b/config/config.go @@ -59,7 +59,7 @@ func Load(p string) *AppConfigs { } func (c *AppConfigs) Save(p string) error { - data, err := json.MarshalIndent(c, "", " ") + data, err := json.MarshalIndent(c, "", " ") if err != nil { return err } diff --git a/internal/constant/errorcode.go b/internal/constant/errorcode.go index 41d4d0f..5057f88 100644 --- a/internal/constant/errorcode.go +++ b/internal/constant/errorcode.go @@ -4,8 +4,9 @@ type ErrorCode int // https://github.com/DarkEnergyProcessor/NPPS4/blob/master/npps4/idol/error.py const ( - ErrorCodeUnknown ErrorCode = 1 ErrorCodeNoUnitIsSellable ErrorCode = 1205 ErrorCodeLivePreciseListNotFound ErrorCode = 3421 ErrorCodeEventNoEventData ErrorCode = 10004 ) + +const ErrorCodeAcceptableError = 600 diff --git a/internal/handler/achievement/pagingaccomplishedlist.go b/internal/handler/achievement/pagingaccomplishedlist.go index 3612137..d621a4b 100644 --- a/internal/handler/achievement/pagingaccomplishedlist.go +++ b/internal/handler/achievement/pagingaccomplishedlist.go @@ -7,6 +7,7 @@ import ( achievementschema "honoka-chan/internal/schema/achievement" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -36,7 +37,7 @@ func pagingAccomplishedList(ctx *gin.Context) { ss.Respond(achievementschema.PagingAccomplishedListResp{ ResponseData: items[start:end], ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/album/seriesall.go b/internal/handler/album/seriesall.go index a3626ed..e943982 100644 --- a/internal/handler/album/seriesall.go +++ b/internal/handler/album/seriesall.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" albumschema "honoka-chan/internal/schema/album" "honoka-chan/internal/session" + "net/http" "github.com/gin-gonic/gin" ) @@ -81,7 +82,7 @@ func seriesAll(ctx *gin.Context) { ss.Respond(albumschema.SeriesAllResp{ ResponseData: albumSeriesAllRes, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/announce/checkstate.go b/internal/handler/announce/checkstate.go index 6eea194..76904b4 100644 --- a/internal/handler/announce/checkstate.go +++ b/internal/handler/announce/checkstate.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" announceschema "honoka-chan/internal/schema/announce" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -20,7 +21,7 @@ func checkState(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/api/achievement/initialaccomplishedlist.go b/internal/handler/api/achievement/initialaccomplishedlist.go index 4fd4c5b..48934ae 100644 --- a/internal/handler/api/achievement/initialaccomplishedlist.go +++ b/internal/handler/api/achievement/initialaccomplishedlist.go @@ -3,6 +3,7 @@ package achievement import ( achievementapischema "honoka-chan/internal/schema/api/achievement" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -37,7 +38,7 @@ func initialAccomplishedList(ctx *gin.Context) (res any, err error) { return achievementapischema.UnaccomplishListResp{ Result: listData, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), }, nil diff --git a/internal/handler/api/achievement/unaccomplishlist.go b/internal/handler/api/achievement/unaccomplishlist.go index a78c7a0..35017dc 100644 --- a/internal/handler/api/achievement/unaccomplishlist.go +++ b/internal/handler/api/achievement/unaccomplishlist.go @@ -2,6 +2,7 @@ package achievement import ( achievementapischema "honoka-chan/internal/schema/api/achievement" + "net/http" "time" ) @@ -18,7 +19,7 @@ func unaccomplishList() (res any, err error) { res = achievementapischema.UnaccomplishListResp{ Result: listData, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/album/all.go b/internal/handler/api/album/all.go index 4fe53c3..11f382a 100644 --- a/internal/handler/api/album/all.go +++ b/internal/handler/api/album/all.go @@ -3,6 +3,7 @@ package album import ( albumapischema "honoka-chan/internal/schema/api/album" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -61,7 +62,7 @@ func albumAll(ctx *gin.Context) (res any, err error) { res = albumapischema.AllResp{ Result: albumLists, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/api.go b/internal/handler/api/api.go index 776b9ec..01d3f15 100644 --- a/internal/handler/api/api.go +++ b/internal/handler/api/api.go @@ -1,7 +1,6 @@ package api import ( - "honoka-chan/internal/constant" "honoka-chan/internal/handler/api/achievement" "honoka-chan/internal/handler/api/album" "honoka-chan/internal/handler/api/award" @@ -33,10 +32,9 @@ import ( "honoka-chan/internal/middleware" "honoka-chan/internal/router" apischema "honoka-chan/internal/schema/api" - commonschema "honoka-chan/internal/schema/common" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" - "time" + "net/http" "github.com/gin-gonic/gin" ) @@ -117,15 +115,8 @@ func api(ctx *gin.Context) { } if honokautils.IsUnimplementedError(err) { - results = append(results, commonschema.ApiErrorResp{ - Result: commonschema.ErrorData{ - ErrorCode: constant.ErrorCodeUnknown, - }, - Status: 600, - CommandNum: false, - TimeStamp: time.Now().Unix(), - }) - continue + ss.AbortWithStatus(http.StatusNotFound, honokautils.NewDetailContent(err.Error())) + return } if ss.CheckErr(err) { return @@ -136,7 +127,7 @@ func api(ctx *gin.Context) { apiResp := apischema.ApiResp{ ResponseData: results, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, } ss.Respond(apiResp) diff --git a/internal/handler/api/award/info.go b/internal/handler/api/award/info.go index a39232c..73df50a 100644 --- a/internal/handler/api/award/info.go +++ b/internal/handler/api/award/info.go @@ -3,6 +3,7 @@ package award import ( awardapischema "honoka-chan/internal/schema/api/award" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -40,7 +41,7 @@ func awardInfo(ctx *gin.Context) (res any, err error) { Result: awardapischema.InfoData{ AwardInfo: awardsList, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/background/info.go b/internal/handler/api/background/info.go index d922afd..a643cfb 100644 --- a/internal/handler/api/background/info.go +++ b/internal/handler/api/background/info.go @@ -3,6 +3,7 @@ package background import ( backgroundapischema "honoka-chan/internal/schema/api/background" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -40,7 +41,7 @@ func backgroundInfo(ctx *gin.Context) (res any, err error) { Result: backgroundapischema.InfoData{ BackgroundInfo: backgroundsList, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/banner/list.go b/internal/handler/api/banner/list.go index 0b1a083..fb8a81b 100644 --- a/internal/handler/api/banner/list.go +++ b/internal/handler/api/banner/list.go @@ -2,6 +2,7 @@ package banner import ( bannerapischema "honoka-chan/internal/schema/api/banner" + "net/http" "time" ) @@ -63,7 +64,7 @@ func bannerList() (res any, err error) { }, }, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/challenge/info.go b/internal/handler/api/challenge/info.go index d214195..ebe430e 100644 --- a/internal/handler/api/challenge/info.go +++ b/internal/handler/api/challenge/info.go @@ -2,13 +2,14 @@ package challenge import ( challengeapischema "honoka-chan/internal/schema/api/challenge" + "net/http" "time" ) func challengeInfo() (res any, err error) { res = challengeapischema.InfoResp{ Result: []any{}, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/costume/list.go b/internal/handler/api/costume/list.go index 40f9dbc..0033545 100644 --- a/internal/handler/api/costume/list.go +++ b/internal/handler/api/costume/list.go @@ -2,6 +2,7 @@ package costume import ( costumeapischema "honoka-chan/internal/schema/api/costume" + "net/http" "time" ) @@ -10,7 +11,7 @@ func costumeList() (res any, err error) { Result: costumeapischema.ListData{ CostumeList: []costumeapischema.CostumeList{}, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/eventscenario/status.go b/internal/handler/api/eventscenario/status.go index 0038df8..1ceb2c7 100644 --- a/internal/handler/api/eventscenario/status.go +++ b/internal/handler/api/eventscenario/status.go @@ -4,6 +4,7 @@ import ( "fmt" eventscenarioapischema "honoka-chan/internal/schema/api/eventscenario" "honoka-chan/internal/session" + "net/http" "strings" "time" @@ -71,7 +72,7 @@ func eventScenarioStatus(ctx *gin.Context) (res any, err error) { Result: eventscenarioapischema.StatusData{ EventScenarioList: eventsList, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/exchange/owningpoint.go b/internal/handler/api/exchange/owningpoint.go index 6be051a..0711525 100644 --- a/internal/handler/api/exchange/owningpoint.go +++ b/internal/handler/api/exchange/owningpoint.go @@ -3,6 +3,7 @@ package exchange import ( exchangeapischema "honoka-chan/internal/schema/api/exchange" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -28,7 +29,7 @@ func owningPoint(ctx *gin.Context) (res any, err error) { Result: exchangeapischema.OwningPointData{ ExchangePointList: exPointsList, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/item/list.go b/internal/handler/api/item/list.go index 6b621e8..19e1964 100644 --- a/internal/handler/api/item/list.go +++ b/internal/handler/api/item/list.go @@ -3,6 +3,7 @@ package item import ( itemapischema "honoka-chan/internal/schema/api/item" honokautils "honoka-chan/internal/utils" + "net/http" "time" ) @@ -14,7 +15,7 @@ func itemList() (res any, err error) { res = itemapischema.ListResp{ Result: itemData, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/live/schedule.go b/internal/handler/api/live/schedule.go index a9ae498..81c9cf1 100644 --- a/internal/handler/api/live/schedule.go +++ b/internal/handler/api/live/schedule.go @@ -3,6 +3,7 @@ package live import ( liveapischema "honoka-chan/internal/schema/api/live" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -36,7 +37,7 @@ func liveSchedule(ctx *gin.Context) (res any, err error) { FreeLiveList: []any{}, TrainingLiveList: []liveapischema.TrainingLiveList{}, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/live/status.go b/internal/handler/api/live/status.go index e094687..95a8013 100644 --- a/internal/handler/api/live/status.go +++ b/internal/handler/api/live/status.go @@ -3,6 +3,7 @@ package live import ( liveapischema "honoka-chan/internal/schema/api/live" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -46,7 +47,7 @@ func liveStatus(ctx *gin.Context) (res any, err error) { FreeLiveStatusList: []any{}, CanResumeLive: true, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/liveicon/info.go b/internal/handler/api/liveicon/info.go index 6138c2c..cb3d298 100644 --- a/internal/handler/api/liveicon/info.go +++ b/internal/handler/api/liveicon/info.go @@ -2,6 +2,7 @@ package liveicon import ( liveiconapischema "honoka-chan/internal/schema/api/liveicon" + "net/http" "time" ) @@ -10,7 +11,7 @@ func liveIconInfo() (res any, err error) { Result: liveiconapischema.InfoData{ LiveNotesIconList: []int{1, 2, 3}, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/livese/info.go b/internal/handler/api/livese/info.go index c2e2fc6..35b4c01 100644 --- a/internal/handler/api/livese/info.go +++ b/internal/handler/api/livese/info.go @@ -2,6 +2,7 @@ package livese import ( liveseapischema "honoka-chan/internal/schema/api/livese" + "net/http" "time" ) @@ -10,7 +11,7 @@ func LiveSeInfo() (res any, err error) { Result: liveseapischema.InfoData{ LiveSeList: []int{1, 2, 3}, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/login/topinfo.go b/internal/handler/api/login/topinfo.go index bf9f0ec..2113ba2 100644 --- a/internal/handler/api/login/topinfo.go +++ b/internal/handler/api/login/topinfo.go @@ -4,6 +4,7 @@ import ( usermodel "honoka-chan/internal/model/user" loginapischema "honoka-chan/internal/schema/api/login" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -68,7 +69,7 @@ func loginTopInfo(ctx *gin.Context) (res any, err error) { AdFlag: false, HasAdReward: false, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: now.Unix(), } diff --git a/internal/handler/api/login/topinfoonce.go b/internal/handler/api/login/topinfoonce.go index 6c47d20..9d6d7fd 100644 --- a/internal/handler/api/login/topinfoonce.go +++ b/internal/handler/api/login/topinfoonce.go @@ -3,6 +3,7 @@ package login import ( loginapischema "honoka-chan/internal/schema/api/login" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -36,7 +37,7 @@ func loginTopInfoOnce(ctx *gin.Context) (res any, err error) { ArenaSiSkillUniqueCheck: true, OpenV98: true, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/marathon/info.go b/internal/handler/api/marathon/info.go index 2fdab8c..e4167a0 100644 --- a/internal/handler/api/marathon/info.go +++ b/internal/handler/api/marathon/info.go @@ -2,13 +2,14 @@ package marathon import ( marathonapischema "honoka-chan/internal/schema/api/marathon" + "net/http" "time" ) func marathonInfo() (res any, err error) { res = marathonapischema.InfoResp{ Result: []any{}, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/multiunit/scenariostatus.go b/internal/handler/api/multiunit/scenariostatus.go index 054c00f..d39d679 100644 --- a/internal/handler/api/multiunit/scenariostatus.go +++ b/internal/handler/api/multiunit/scenariostatus.go @@ -3,6 +3,7 @@ package multiunit import ( multiunitapischema "honoka-chan/internal/schema/api/multiunit" "honoka-chan/internal/session" + "net/http" "strings" "time" @@ -53,7 +54,7 @@ func MultiUnitScenarioStatus(ctx *gin.Context) (res any, err error) { MultiUnitScenarioStatusList: multiUnitsList, UnlockedMultiUnitScenarioIds: []any{}, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/museum/info.go b/internal/handler/api/museum/info.go index aaf9816..8cfef9b 100644 --- a/internal/handler/api/museum/info.go +++ b/internal/handler/api/museum/info.go @@ -3,6 +3,7 @@ package museum import ( museumapischema "honoka-chan/internal/schema/api/museum" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -42,7 +43,7 @@ func museumInfo(ctx *gin.Context) (res any, err error) { ContentsIDList: museumID, }, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/navigation/specialcutin.go b/internal/handler/api/navigation/specialcutin.go index 998524f..f708d90 100644 --- a/internal/handler/api/navigation/specialcutin.go +++ b/internal/handler/api/navigation/specialcutin.go @@ -2,6 +2,7 @@ package navigation import ( navigationapischema "honoka-chan/internal/schema/api/navigation" + "net/http" "time" ) @@ -10,7 +11,7 @@ func SpecialCutin() (res any, err error) { Result: navigationapischema.SpecialCutinData{ SpecialCutinList: []any{}, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/notice/marquee.go b/internal/handler/api/notice/marquee.go index 16aa61e..b8f74d4 100644 --- a/internal/handler/api/notice/marquee.go +++ b/internal/handler/api/notice/marquee.go @@ -2,6 +2,7 @@ package notice import ( noticeapischema "honoka-chan/internal/schema/api/notice" + "net/http" "time" ) @@ -11,7 +12,7 @@ func noticeMarquee() (res any, err error) { ItemCount: 0, MarqueeList: []any{}, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/payment/productlist.go b/internal/handler/api/payment/productlist.go index 436bedf..797333d 100644 --- a/internal/handler/api/payment/productlist.go +++ b/internal/handler/api/payment/productlist.go @@ -3,6 +3,7 @@ package payment import ( paymentapischema "honoka-chan/internal/schema/api/payment" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -27,7 +28,7 @@ func productList(ctx *gin.Context) (res any, err error) { SubscriptionList: []paymentapischema.Subscription{}, ShowPointShop: false, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/profile/cardranking.go b/internal/handler/api/profile/cardranking.go index 6aba65b..0dd74ca 100644 --- a/internal/handler/api/profile/cardranking.go +++ b/internal/handler/api/profile/cardranking.go @@ -3,6 +3,7 @@ package profile import ( profileapischema "honoka-chan/internal/schema/api/profile" honokautils "honoka-chan/internal/utils" + "net/http" "time" ) @@ -14,7 +15,7 @@ func cardRanking() (res any, err error) { res = profileapischema.CardRankingResp{ Result: cardRankingData, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/profile/info.go b/internal/handler/api/profile/info.go index 37da0a5..3d67769 100644 --- a/internal/handler/api/profile/info.go +++ b/internal/handler/api/profile/info.go @@ -6,6 +6,7 @@ import ( usermodel "honoka-chan/internal/model/user" profileapischema "honoka-chan/internal/schema/api/profile" "honoka-chan/internal/session" + "net/http" "strconv" "time" @@ -89,7 +90,7 @@ func profileInfo(ctx *gin.Context, targetUserID int) (res any, err error) { SettingAwardID: targetPref.AwardID, SettingBackgroundID: targetPref.BackgroundID, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/profile/livecnt.go b/internal/handler/api/profile/livecnt.go index 9859101..84a4c5a 100644 --- a/internal/handler/api/profile/livecnt.go +++ b/internal/handler/api/profile/livecnt.go @@ -4,6 +4,7 @@ import ( usermodel "honoka-chan/internal/model/user" profileapischema "honoka-chan/internal/schema/api/profile" "honoka-chan/internal/session" + "net/http" "sort" "time" @@ -82,7 +83,7 @@ func liveCnt(ctx *gin.Context, targetUserID int) (res any, err error) { res = profileapischema.LiveCntResp{ Result: result, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/reward/history.go b/internal/handler/api/reward/history.go index 50feb60..d931082 100644 --- a/internal/handler/api/reward/history.go +++ b/internal/handler/api/reward/history.go @@ -2,6 +2,7 @@ package reward import ( rewardapischema "honoka-chan/internal/schema/api/reward" + "net/http" "time" ) @@ -12,7 +13,7 @@ func rewardHistory() (res any, err error) { Limit: 20, History: []any{}, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/reward/list.go b/internal/handler/api/reward/list.go index 313c101..7b54c12 100644 --- a/internal/handler/api/reward/list.go +++ b/internal/handler/api/reward/list.go @@ -2,6 +2,7 @@ package reward import ( rewardapischema "honoka-chan/internal/schema/api/reward" + "net/http" "time" ) @@ -13,7 +14,7 @@ func rewardList() (res any, err error) { Order: 0, Items: []any{}, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/scenario/status.go b/internal/handler/api/scenario/status.go index ff6b638..e8c155a 100644 --- a/internal/handler/api/scenario/status.go +++ b/internal/handler/api/scenario/status.go @@ -3,6 +3,7 @@ package scenario import ( scenarioapischema "honoka-chan/internal/schema/api/scenario" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -28,7 +29,7 @@ func scenarioStatus(ctx *gin.Context) (res any, err error) { Result: scenarioapischema.StatusData{ ScenarioStatusList: scenarioLists, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/secretbox/all.go b/internal/handler/api/secretbox/all.go index 9a5d4bd..d15ee13 100644 --- a/internal/handler/api/secretbox/all.go +++ b/internal/handler/api/secretbox/all.go @@ -3,6 +3,7 @@ package secretbox import ( secretboxapischema "honoka-chan/internal/schema/api/secretbox" honokautils "honoka-chan/internal/utils" + "net/http" "time" ) @@ -35,7 +36,7 @@ func all() (res any, err error) { res = secretboxapischema.AllResp{ Result: secretBoxData, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/stamp/info.go b/internal/handler/api/stamp/info.go index c491606..dc02762 100644 --- a/internal/handler/api/stamp/info.go +++ b/internal/handler/api/stamp/info.go @@ -3,6 +3,7 @@ package stamp import ( stampapischema "honoka-chan/internal/schema/api/stamp" honokautils "honoka-chan/internal/utils" + "net/http" "time" ) @@ -14,7 +15,7 @@ func stampInfo() (res any, err error) { res = stampapischema.InfoResp{ Result: stampData, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/subscenario/status.go b/internal/handler/api/subscenario/status.go index a418fcf..1febf18 100644 --- a/internal/handler/api/subscenario/status.go +++ b/internal/handler/api/subscenario/status.go @@ -3,6 +3,7 @@ package subscenario import ( subscenarioapischema "honoka-chan/internal/schema/api/subscenario" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -29,7 +30,7 @@ func subscenarioStatus(ctx *gin.Context) (res any, err error) { SubscenarioStatusList: subScenarioLists, UnlockedSubscenarioIds: []any{}, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/unit/accessoryall.go b/internal/handler/api/unit/accessoryall.go index 2f3ec89..6459dd0 100644 --- a/internal/handler/api/unit/accessoryall.go +++ b/internal/handler/api/unit/accessoryall.go @@ -3,6 +3,7 @@ package unit import ( unitapischema "honoka-chan/internal/schema/api/unit" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -34,7 +35,7 @@ func unitAccessoryAll(ctx *gin.Context) (res any, err error) { WearingInfo: wearingInfo, EspecialCreateFlag: false, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/unit/accessorymaterialall.go b/internal/handler/api/unit/accessorymaterialall.go index 474215f..eb2d1a4 100644 --- a/internal/handler/api/unit/accessorymaterialall.go +++ b/internal/handler/api/unit/accessorymaterialall.go @@ -2,13 +2,14 @@ package unit import ( unitapischema "honoka-chan/internal/schema/api/unit" + "net/http" "time" ) func unitAccessoryMaterialAll() (res any, err error) { res = unitapischema.AccessoryMaterialAllResp{ Result: unitapischema.AccessoryMaterialAllData{}, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/unit/accessorytab.go b/internal/handler/api/unit/accessorytab.go index 0bb0fe6..3fd9d1f 100644 --- a/internal/handler/api/unit/accessorytab.go +++ b/internal/handler/api/unit/accessorytab.go @@ -3,6 +3,7 @@ package unit import ( unitapischema "honoka-chan/internal/schema/api/unit" honokautils "honoka-chan/internal/utils" + "net/http" "time" ) @@ -16,7 +17,7 @@ func unitAccessoryTab() (res any, err error) { Result: unitapischema.AccessoryTabData{ TabList: tabList, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/unit/all.go b/internal/handler/api/unit/all.go index f89315f..da7663e 100644 --- a/internal/handler/api/unit/all.go +++ b/internal/handler/api/unit/all.go @@ -4,6 +4,7 @@ import ( unitmodel "honoka-chan/internal/model/unit" unitapischema "honoka-chan/internal/schema/api/unit" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -55,7 +56,7 @@ func unitAll(ctx *gin.Context) (res any, err error) { Active: unitsData, Waiting: []unitapischema.Waiting{}, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/unit/deckinfo.go b/internal/handler/api/unit/deckinfo.go index 7575985..3ab4500 100644 --- a/internal/handler/api/unit/deckinfo.go +++ b/internal/handler/api/unit/deckinfo.go @@ -3,6 +3,7 @@ package unit import ( unitapischema "honoka-chan/internal/schema/api/unit" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -46,7 +47,7 @@ func unitDeckInfo(ctx *gin.Context) (res any, err error) { } res = unitapischema.DeckInfoResp{ Result: unitDeckInfo, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/unit/removableskillinfo.go b/internal/handler/api/unit/removableskillinfo.go index edb0da5..78ef8a1 100644 --- a/internal/handler/api/unit/removableskillinfo.go +++ b/internal/handler/api/unit/removableskillinfo.go @@ -3,6 +3,7 @@ package unit import ( unitapischema "honoka-chan/internal/schema/api/unit" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -67,7 +68,7 @@ func unitRemovableSkillInfo(ctx *gin.Context) (res any, err error) { OwningInfo: owingInfo, EquipmentInfo: equipInfo, }, // 宝石 - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/unit/supporterall.go b/internal/handler/api/unit/supporterall.go index 1d2dc05..818959a 100644 --- a/internal/handler/api/unit/supporterall.go +++ b/internal/handler/api/unit/supporterall.go @@ -2,6 +2,7 @@ package unit import ( unitapischema "honoka-chan/internal/schema/api/unit" + "net/http" "time" ) @@ -10,7 +11,7 @@ func unitSupporterAll() (res any, err error) { Result: unitapischema.SupporterAllData{ UnitSupportList: []unitapischema.SupporterList{}, }, // 练习道具 - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/user/getnavi.go b/internal/handler/api/user/getnavi.go index 5cc5f79..406f799 100644 --- a/internal/handler/api/user/getnavi.go +++ b/internal/handler/api/user/getnavi.go @@ -3,6 +3,7 @@ package user import ( userapischema "honoka-chan/internal/schema/api/user" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -24,7 +25,7 @@ func userGetNavi(ctx *gin.Context) (res any, err error) { UnitOwningUserID: oID, }, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/api/user/info.go b/internal/handler/api/user/info.go index 3936b78..6e232f4 100644 --- a/internal/handler/api/user/info.go +++ b/internal/handler/api/user/info.go @@ -4,6 +4,7 @@ import ( userapischema "honoka-chan/internal/schema/api/user" userschema "honoka-chan/internal/schema/user" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -20,7 +21,7 @@ func userInfo(ctx *gin.Context) (res any, err error) { BirthDay: ss.UserPref.EffectiveBirthDay(), }, }, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), } diff --git a/internal/handler/award/set.go b/internal/handler/award/set.go index da2fca3..ec5e41b 100644 --- a/internal/handler/award/set.go +++ b/internal/handler/award/set.go @@ -6,6 +6,7 @@ import ( "honoka-chan/internal/router" awardschema "honoka-chan/internal/schema/award" "honoka-chan/internal/session" + "net/http" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" @@ -28,7 +29,7 @@ func set(ctx *gin.Context) { ss.Respond(awardschema.SetResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/background/set.go b/internal/handler/background/set.go index 36d705d..53b6a8f 100644 --- a/internal/handler/background/set.go +++ b/internal/handler/background/set.go @@ -6,6 +6,7 @@ import ( "honoka-chan/internal/router" backgroundschema "honoka-chan/internal/schema/background" "honoka-chan/internal/session" + "net/http" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" @@ -28,7 +29,7 @@ func set(ctx *gin.Context) { ss.Respond(backgroundschema.SetResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/banner/list.go b/internal/handler/banner/list.go index 06c63a9..397df28 100644 --- a/internal/handler/banner/list.go +++ b/internal/handler/banner/list.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/middleware" "honoka-chan/internal/router" "honoka-chan/internal/session" + "net/http" "github.com/gin-gonic/gin" ) @@ -33,7 +34,7 @@ func list(ctx *gin.Context) { ss.Respond(bannerResp{ ResponseData: extractBannerResult(data), ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/download/additional.go b/internal/handler/download/additional.go index 9457562..07f7678 100644 --- a/internal/handler/download/additional.go +++ b/internal/handler/download/additional.go @@ -8,6 +8,7 @@ import ( downloadschema "honoka-chan/internal/schema/download" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -42,7 +43,7 @@ func additional(ctx *gin.Context) { ss.Respond(downloadschema.AdditionalResp{ ResponseData: pkgList, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/download/batch.go b/internal/handler/download/batch.go index 9c24cfa..9a4b7b7 100644 --- a/internal/handler/download/batch.go +++ b/internal/handler/download/batch.go @@ -8,6 +8,7 @@ import ( downloadschema "honoka-chan/internal/schema/download" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" "xorm.io/builder" @@ -57,7 +58,7 @@ func batch(ctx *gin.Context) { ss.Respond(downloadschema.BatchResp{ ResponseData: pkgList, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/download/event.go b/internal/handler/download/event.go index f0e973f..c1e4fc5 100644 --- a/internal/handler/download/event.go +++ b/internal/handler/download/event.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" downloadschema "honoka-chan/internal/schema/download" "honoka-chan/internal/session" + "net/http" "github.com/gin-gonic/gin" ) @@ -16,7 +17,7 @@ func event(ctx *gin.Context) { ss.Respond(downloadschema.EventResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/download/geturl.go b/internal/handler/download/geturl.go index e6fab4c..ee227e1 100644 --- a/internal/handler/download/geturl.go +++ b/internal/handler/download/geturl.go @@ -8,6 +8,7 @@ import ( downloadschema "honoka-chan/internal/schema/download" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "strings" "github.com/gin-gonic/gin" @@ -34,7 +35,7 @@ func getUrl(ctx *gin.Context) { UrlList: urlList, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/download/update.go b/internal/handler/download/update.go index 0e8ecfe..af200ac 100644 --- a/internal/handler/download/update.go +++ b/internal/handler/download/update.go @@ -64,7 +64,7 @@ func update(ctx *gin.Context) { ss.Respond(downloadschema.UpdateResp{ ResponseData: pkgList, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/event/list.go b/internal/handler/event/list.go index bf55a68..4c7f1f8 100644 --- a/internal/handler/event/list.go +++ b/internal/handler/event/list.go @@ -28,7 +28,7 @@ func list(ctx *gin.Context) { ErrorCode: constant.ErrorCodeEventNoEventData, }, ReleaseInfo: []any{}, - StatusCode: 600, + StatusCode: constant.ErrorCodeAcceptableError, }) } diff --git a/internal/handler/eventscenario/startup.go b/internal/handler/eventscenario/startup.go index 70ad516..1f4ee55 100644 --- a/internal/handler/eventscenario/startup.go +++ b/internal/handler/eventscenario/startup.go @@ -6,6 +6,7 @@ import ( eventscenarioschema "honoka-chan/internal/schema/eventscenario" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -23,7 +24,7 @@ func startup(ctx *gin.Context) { ss.Respond(eventscenarioschema.StartUpResp{ ResponseData: eventscenarioschema.StartUpData{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/friend/expel.go b/internal/handler/friend/expel.go index 04aff7d..060eb08 100644 --- a/internal/handler/friend/expel.go +++ b/internal/handler/friend/expel.go @@ -7,6 +7,7 @@ import ( friendschema "honoka-chan/internal/schema/friend" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -45,7 +46,7 @@ func expel(ctx *gin.Context) { ss.Respond(friendschema.ExpelResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/friend/list.go b/internal/handler/friend/list.go index 3b4c6b5..f0deb6e 100644 --- a/internal/handler/friend/list.go +++ b/internal/handler/friend/list.go @@ -9,6 +9,7 @@ import ( friendschema "honoka-chan/internal/schema/friend" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "strconv" "time" @@ -121,7 +122,7 @@ func list(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/friend/request.go b/internal/handler/friend/request.go index 1982af7..5d495a4 100644 --- a/internal/handler/friend/request.go +++ b/internal/handler/friend/request.go @@ -8,6 +8,7 @@ import ( friendschema "honoka-chan/internal/schema/friend" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -41,7 +42,7 @@ func request(ctx *gin.Context) { IsFriend: true, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) return } @@ -75,7 +76,7 @@ func request(ctx *gin.Context) { IsFriend: true, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) return } @@ -94,7 +95,7 @@ func request(ctx *gin.Context) { IsFriend: false, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/friend/requestcancel.go b/internal/handler/friend/requestcancel.go index ce6efb5..c1b40ef 100644 --- a/internal/handler/friend/requestcancel.go +++ b/internal/handler/friend/requestcancel.go @@ -7,6 +7,7 @@ import ( friendschema "honoka-chan/internal/schema/friend" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -54,7 +55,7 @@ func requestCancel(ctx *gin.Context) { IsFriend: isFriend, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/friend/response.go b/internal/handler/friend/response.go index 161c061..2ad3207 100644 --- a/internal/handler/friend/response.go +++ b/internal/handler/friend/response.go @@ -8,6 +8,7 @@ import ( friendschema "honoka-chan/internal/schema/friend" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -59,7 +60,7 @@ func response(ctx *gin.Context) { ss.Respond(friendschema.ResponseResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/friend/search.go b/internal/handler/friend/search.go index efe4931..8c0ce38 100644 --- a/internal/handler/friend/search.go +++ b/internal/handler/friend/search.go @@ -9,6 +9,7 @@ import ( friendschema "honoka-chan/internal/schema/friend" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "time" "github.com/gin-gonic/gin" @@ -112,7 +113,7 @@ func search(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/gdpr/get.go b/internal/handler/gdpr/get.go index 0b13ba3..540eb77 100644 --- a/internal/handler/gdpr/get.go +++ b/internal/handler/gdpr/get.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" gdprschema "honoka-chan/internal/schema/gdpr" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -21,7 +22,7 @@ func get(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/greet/delete.go b/internal/handler/greet/delete.go index 63f1628..32481c8 100644 --- a/internal/handler/greet/delete.go +++ b/internal/handler/greet/delete.go @@ -2,6 +2,7 @@ package greet import ( "errors" + "net/http" "honoka-chan/internal/middleware" usermodel "honoka-chan/internal/model/user" @@ -57,7 +58,7 @@ func deleteMail(ctx *gin.Context) { ss.Respond(greetschema.EmptyResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/greet/user.go b/internal/handler/greet/user.go index bbc29f2..d72a02a 100644 --- a/internal/handler/greet/user.go +++ b/internal/handler/greet/user.go @@ -2,6 +2,7 @@ package greet import ( "errors" + "net/http" "strings" "time" @@ -76,7 +77,7 @@ func user(ctx *gin.Context) { ss.Respond(greetschema.EmptyResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/lbonus/execute.go b/internal/handler/lbonus/execute.go index 0e32f67..bba97c0 100644 --- a/internal/handler/lbonus/execute.go +++ b/internal/handler/lbonus/execute.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" lbonusschema "honoka-chan/internal/schema/lbonus" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -148,7 +149,7 @@ func execute(ctx *gin.Context) { PresentCnt: 0, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, } ss.Respond(resp) diff --git a/internal/handler/live/continue.go b/internal/handler/live/continue.go index 3a87534..61dfb2f 100644 --- a/internal/handler/live/continue.go +++ b/internal/handler/live/continue.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" liveschema "honoka-chan/internal/schema/live" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -25,7 +26,7 @@ func BuildContinueResp(ss *session.Session) liveschema.ContinueResp { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, } } diff --git a/internal/handler/live/gameover.go b/internal/handler/live/gameover.go index 103227f..7fa63a1 100644 --- a/internal/handler/live/gameover.go +++ b/internal/handler/live/gameover.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" liveschema "honoka-chan/internal/schema/live" "honoka-chan/internal/session" + "net/http" "github.com/gin-gonic/gin" ) @@ -25,7 +26,7 @@ func BuildGameOverResp() liveschema.GameOverResp { return liveschema.GameOverResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, } } diff --git a/internal/handler/live/partylist.go b/internal/handler/live/partylist.go index f7f5ad7..7506f21 100644 --- a/internal/handler/live/partylist.go +++ b/internal/handler/live/partylist.go @@ -6,6 +6,7 @@ import ( "honoka-chan/internal/router" liveschema "honoka-chan/internal/schema/live" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -22,7 +23,7 @@ func partyList(ctx *gin.Context) { ss.Respond(liveschema.PartyListResp{ ResponseData: partyListData, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/live/play.go b/internal/handler/live/play.go index d8f3b56..59c6762 100644 --- a/internal/handler/live/play.go +++ b/internal/handler/live/play.go @@ -8,6 +8,7 @@ import ( "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" "math" + "net/http" "strconv" "time" @@ -322,7 +323,7 @@ func BuildPlayResp(ss *session.Session, playReq liveschema.PlayReq, isRandom boo ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }, nil } diff --git a/internal/handler/live/precisescore.go b/internal/handler/live/precisescore.go index 86ac327..5e1a550 100644 --- a/internal/handler/live/precisescore.go +++ b/internal/handler/live/precisescore.go @@ -10,6 +10,7 @@ import ( liverecordschema "honoka-chan/internal/schema/liverecord" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "time" "github.com/gin-gonic/gin" @@ -88,7 +89,7 @@ func preciseScore(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, } } else { // 如果有 Live 记录 @@ -181,7 +182,7 @@ func preciseScore(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, } } else { playResp = liveschema.PreciseScoreResp{ @@ -189,7 +190,7 @@ func preciseScore(ctx *gin.Context) { ErrorCode: constant.ErrorCodeLivePreciseListNotFound, }, ReleaseInfo: []any{}, - StatusCode: 600, + StatusCode: constant.ErrorCodeAcceptableError, } } } diff --git a/internal/handler/live/reward.go b/internal/handler/live/reward.go index bc7db2c..b590228 100644 --- a/internal/handler/live/reward.go +++ b/internal/handler/live/reward.go @@ -9,6 +9,7 @@ import ( "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" "honoka-chan/pkg/utils" + "net/http" "time" "github.com/gin-gonic/gin" @@ -172,7 +173,7 @@ func BuildRewardResp(ss *session.Session, playRewardReq liveschema.RewardReq, is PresentCnt: 0, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, } if playRewardReq.MaxCombo >= liveInfo.SRankCombo { diff --git a/internal/handler/login/authkey.go b/internal/handler/login/authkey.go index c79aff1..6a54ef8 100644 --- a/internal/handler/login/authkey.go +++ b/internal/handler/login/authkey.go @@ -9,6 +9,7 @@ import ( "honoka-chan/internal/session" "honoka-chan/pkg/encrypt" utils "honoka-chan/pkg/utils" + "net/http" "time" "github.com/gin-gonic/gin" @@ -51,7 +52,7 @@ func authKey(ctx *gin.Context) { DummyToken: serverToken, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/login/login.go b/internal/handler/login/login.go index ced9d65..d6feccb 100644 --- a/internal/handler/login/login.go +++ b/internal/handler/login/login.go @@ -10,6 +10,7 @@ import ( "honoka-chan/internal/session" "honoka-chan/pkg/encrypt" "honoka-chan/pkg/utils" + "net/http" "time" "github.com/gin-gonic/gin" @@ -81,7 +82,7 @@ func login(ctx *gin.Context) { AdultFlag: 2, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/multiunit/scenariostartup.go b/internal/handler/multiunit/scenariostartup.go index ec84661..0a80b22 100644 --- a/internal/handler/multiunit/scenariostartup.go +++ b/internal/handler/multiunit/scenariostartup.go @@ -6,6 +6,7 @@ import ( multiunitschema "honoka-chan/internal/schema/multiunit" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "time" "github.com/gin-gonic/gin" @@ -28,7 +29,7 @@ func scenarioStartup(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/museum/info.go b/internal/handler/museum/info.go index cd87c79..9bd19f0 100644 --- a/internal/handler/museum/info.go +++ b/internal/handler/museum/info.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" museumschema "honoka-chan/internal/schema/museum" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -46,7 +47,7 @@ func info(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, } ss.Respond(museumResp) diff --git a/internal/handler/notice/friendgreeting.go b/internal/handler/notice/friendgreeting.go index cc64b2e..89a1591 100644 --- a/internal/handler/notice/friendgreeting.go +++ b/internal/handler/notice/friendgreeting.go @@ -7,6 +7,7 @@ import ( noticeschema "honoka-chan/internal/schema/notice" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "time" "github.com/gin-gonic/gin" @@ -80,7 +81,7 @@ func friendGreeting(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/notice/friendvariety.go b/internal/handler/notice/friendvariety.go index 721f68b..a5aedd4 100644 --- a/internal/handler/notice/friendvariety.go +++ b/internal/handler/notice/friendvariety.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" noticeschema "honoka-chan/internal/schema/notice" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -21,7 +22,7 @@ func friendVariety(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/notice/usergreetinghistory.go b/internal/handler/notice/usergreetinghistory.go index e8e55c4..0416fde 100644 --- a/internal/handler/notice/usergreetinghistory.go +++ b/internal/handler/notice/usergreetinghistory.go @@ -7,6 +7,7 @@ import ( noticeschema "honoka-chan/internal/schema/notice" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "time" "github.com/gin-gonic/gin" @@ -68,7 +69,7 @@ func userGreetingHistory(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/payment/productlist.go b/internal/handler/payment/productlist.go index bfaf23c..2d8bcc4 100644 --- a/internal/handler/payment/productlist.go +++ b/internal/handler/payment/productlist.go @@ -6,6 +6,7 @@ import ( paymentapischema "honoka-chan/internal/schema/api/payment" paymentschema "honoka-chan/internal/schema/payment" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -33,7 +34,7 @@ func productList(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, } ss.Respond(prodResp) diff --git a/internal/handler/personalnotice/get.go b/internal/handler/personalnotice/get.go index b6b0b0a..f2e9baf 100644 --- a/internal/handler/personalnotice/get.go +++ b/internal/handler/personalnotice/get.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" personalnoticeschema "honoka-chan/internal/schema/personalnotice" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -24,7 +25,7 @@ func get(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, } ss.Respond(noticeResp) diff --git a/internal/handler/profile/register.go b/internal/handler/profile/register.go index bab47c7..72016b2 100644 --- a/internal/handler/profile/register.go +++ b/internal/handler/profile/register.go @@ -6,6 +6,7 @@ import ( "honoka-chan/internal/router" profileschema "honoka-chan/internal/schema/profile" "honoka-chan/internal/session" + "net/http" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" @@ -28,7 +29,7 @@ func register(ctx *gin.Context) { ss.Respond(profileschema.RegisterResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/ranking/live.go b/internal/handler/ranking/live.go index c602b1a..d909272 100644 --- a/internal/handler/ranking/live.go +++ b/internal/handler/ranking/live.go @@ -9,6 +9,7 @@ import ( rankingschema "honoka-chan/internal/schema/ranking" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "strconv" "github.com/gin-gonic/gin" @@ -103,7 +104,7 @@ func live(ctx *gin.Context) { Page: page, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/reward/history.go b/internal/handler/reward/history.go index 048fc51..81eb8f8 100644 --- a/internal/handler/reward/history.go +++ b/internal/handler/reward/history.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" rewardschema "honoka-chan/internal/schema/reward" "honoka-chan/internal/session" + "net/http" "github.com/gin-gonic/gin" ) @@ -20,7 +21,7 @@ func history(ctx *gin.Context) { History: []any{}, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/reward/list.go b/internal/handler/reward/list.go index d6c082e..8c99e61 100644 --- a/internal/handler/reward/list.go +++ b/internal/handler/reward/list.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" rewardschema "honoka-chan/internal/schema/reward" "honoka-chan/internal/session" + "net/http" "github.com/gin-gonic/gin" ) @@ -21,7 +22,7 @@ func list(ctx *gin.Context) { Items: []any{}, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/reward/sellunit.go b/internal/handler/reward/sellunit.go index 29611d0..f277df4 100644 --- a/internal/handler/reward/sellunit.go +++ b/internal/handler/reward/sellunit.go @@ -20,7 +20,7 @@ func sellUnit(ctx *gin.Context) { ErrorCode: constant.ErrorCodeNoUnitIsSellable, }, ReleaseInfo: []any{}, - StatusCode: 600, + StatusCode: constant.ErrorCodeAcceptableError, }) } diff --git a/internal/handler/rlive/lot.go b/internal/handler/rlive/lot.go index d946a6d..b728b03 100644 --- a/internal/handler/rlive/lot.go +++ b/internal/handler/rlive/lot.go @@ -12,6 +12,7 @@ import ( honokautils "honoka-chan/internal/utils" pkgutils "honoka-chan/pkg/utils" "math/big" + "net/http" "os" "path/filepath" "time" @@ -67,7 +68,7 @@ func lot(ctx *gin.Context) { Token: randomLive.Token, }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/scenario/startup.go b/internal/handler/scenario/startup.go index 3911eee..f44dc22 100644 --- a/internal/handler/scenario/startup.go +++ b/internal/handler/scenario/startup.go @@ -6,6 +6,7 @@ import ( "honoka-chan/internal/router" scenarioschema "honoka-chan/internal/schema/scenario" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -28,7 +29,7 @@ func startup(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/secretbox/multi.go b/internal/handler/secretbox/multi.go index fb0dde8..f9b7275 100644 --- a/internal/handler/secretbox/multi.go +++ b/internal/handler/secretbox/multi.go @@ -6,6 +6,7 @@ import ( secretboxschema "honoka-chan/internal/schema/secretbox" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -28,7 +29,7 @@ func multi(ctx *gin.Context) { ss.Respond(secretboxschema.MultiResp{ ResponseData: data, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/secretbox/pon.go b/internal/handler/secretbox/pon.go index 564300d..292f119 100644 --- a/internal/handler/secretbox/pon.go +++ b/internal/handler/secretbox/pon.go @@ -10,6 +10,7 @@ import ( "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" "math/rand" + "net/http" "time" "github.com/gin-gonic/gin" @@ -33,7 +34,7 @@ func pon(ctx *gin.Context) { ss.Respond(secretboxschema.PonResp{ ResponseData: data, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/secretbox/secretbox.go b/internal/handler/secretbox/secretbox.go index 8d13758..05ea220 100644 --- a/internal/handler/secretbox/secretbox.go +++ b/internal/handler/secretbox/secretbox.go @@ -7,6 +7,7 @@ import ( "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" "honoka-chan/pkg/db" + "net/http" "sort" "time" ) @@ -21,7 +22,7 @@ func loadSecretBoxAllData() (secretboxapischema.AllResp, error) { return secretboxapischema.AllResp{ Result: data, - Status: 200, + Status: http.StatusOK, CommandNum: false, TimeStamp: time.Now().Unix(), }, nil diff --git a/internal/handler/secretbox/showdetail.go b/internal/handler/secretbox/showdetail.go index 47b0cf3..6dfd87a 100644 --- a/internal/handler/secretbox/showdetail.go +++ b/internal/handler/secretbox/showdetail.go @@ -7,6 +7,7 @@ import ( secretboxschema "honoka-chan/internal/schema/secretbox" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -29,7 +30,7 @@ func showDetail(ctx *gin.Context) { ss.Respond(secretboxschema.ShowDetailResp{ ResponseData: data, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/subscenario/startup.go b/internal/handler/subscenario/startup.go index 5716d62..b75a066 100644 --- a/internal/handler/subscenario/startup.go +++ b/internal/handler/subscenario/startup.go @@ -6,6 +6,7 @@ import ( subscenarioschema "honoka-chan/internal/schema/subscenario" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "time" "github.com/gin-gonic/gin" @@ -28,7 +29,7 @@ func startup(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/tos/check.go b/internal/handler/tos/check.go index ebd5f5b..9d12baf 100644 --- a/internal/handler/tos/check.go +++ b/internal/handler/tos/check.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" tosschema "honoka-chan/internal/schema/tos" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -22,7 +23,7 @@ func check(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/unit/deck.go b/internal/handler/unit/deck.go index 7849a95..6b217d7 100644 --- a/internal/handler/unit/deck.go +++ b/internal/handler/unit/deck.go @@ -9,6 +9,7 @@ import ( unitschema "honoka-chan/internal/schema/unit" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "time" "github.com/gin-gonic/gin" @@ -101,7 +102,7 @@ func deck(ctx *gin.Context) { ss.Respond(unitschema.DeckResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/unit/deckname.go b/internal/handler/unit/deckname.go index b9387a5..95851b6 100644 --- a/internal/handler/unit/deckname.go +++ b/internal/handler/unit/deckname.go @@ -7,6 +7,7 @@ import ( unitschema "honoka-chan/internal/schema/unit" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -40,7 +41,7 @@ func deckName(ctx *gin.Context) { ss.Respond(unitschema.DeckResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/unit/favorite.go b/internal/handler/unit/favorite.go index abf5be6..17933e1 100644 --- a/internal/handler/unit/favorite.go +++ b/internal/handler/unit/favorite.go @@ -7,6 +7,7 @@ import ( unitschema "honoka-chan/internal/schema/unit" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -33,7 +34,7 @@ func favorite(ctx *gin.Context) { ss.Respond(unitschema.FavoriteResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/unit/favoriteaccessory.go b/internal/handler/unit/favoriteaccessory.go index 9530c01..07c0c35 100644 --- a/internal/handler/unit/favoriteaccessory.go +++ b/internal/handler/unit/favoriteaccessory.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/middleware" "honoka-chan/internal/router" "honoka-chan/internal/session" + "net/http" "github.com/gin-gonic/gin" ) @@ -24,7 +25,7 @@ func favoriteAccessory(ctx *gin.Context) { ss.Respond(SetResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/unit/removableskillequipment.go b/internal/handler/unit/removableskillequipment.go index 1c4d284..27fc50c 100644 --- a/internal/handler/unit/removableskillequipment.go +++ b/internal/handler/unit/removableskillequipment.go @@ -6,6 +6,7 @@ import ( unitschema "honoka-chan/internal/schema/unit" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -48,7 +49,7 @@ func removableSkillEquipment(ctx *gin.Context) { ss.Respond(unitschema.RemovableSkillEquipmentResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/unit/sale.go b/internal/handler/unit/sale.go index b16a030..cc98c1d 100644 --- a/internal/handler/unit/sale.go +++ b/internal/handler/unit/sale.go @@ -7,6 +7,7 @@ import ( unitschema "honoka-chan/internal/schema/unit" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "time" "github.com/gin-gonic/gin" @@ -90,7 +91,7 @@ func sale(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/unit/setdisplayrank.go b/internal/handler/unit/setdisplayrank.go index 18e755f..53fccb6 100644 --- a/internal/handler/unit/setdisplayrank.go +++ b/internal/handler/unit/setdisplayrank.go @@ -7,6 +7,7 @@ import ( unitschema "honoka-chan/internal/schema/unit" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -33,7 +34,7 @@ func setDisplayRank(ctx *gin.Context) { ss.Respond(unitschema.SetDisplayRankResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/unit/wearaccessory.go b/internal/handler/unit/wearaccessory.go index b38d585..8796231 100644 --- a/internal/handler/unit/wearaccessory.go +++ b/internal/handler/unit/wearaccessory.go @@ -8,6 +8,7 @@ import ( unitschema "honoka-chan/internal/schema/unit" "honoka-chan/internal/session" honokautils "honoka-chan/internal/utils" + "net/http" "github.com/gin-gonic/gin" ) @@ -62,7 +63,7 @@ func wearAccessory(ctx *gin.Context) { ss.Respond(unitschema.WearAccessoryResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/user/changename.go b/internal/handler/user/changename.go index 23ba9d5..d5f00e3 100644 --- a/internal/handler/user/changename.go +++ b/internal/handler/user/changename.go @@ -6,6 +6,7 @@ import ( "honoka-chan/internal/router" userschema "honoka-chan/internal/schema/user" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -38,7 +39,7 @@ func changeName(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/user/changenavi.go b/internal/handler/user/changenavi.go index e41d05a..1b46748 100644 --- a/internal/handler/user/changenavi.go +++ b/internal/handler/user/changenavi.go @@ -6,6 +6,7 @@ import ( "honoka-chan/internal/router" userschema "honoka-chan/internal/schema/user" "honoka-chan/internal/session" + "net/http" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" @@ -27,7 +28,7 @@ func changeNavi(ctx *gin.Context) { ss.Respond(userschema.ChangeNaviResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/user/setnotificationtoken.go b/internal/handler/user/setnotificationtoken.go index 6b97a70..2a03d54 100644 --- a/internal/handler/user/setnotificationtoken.go +++ b/internal/handler/user/setnotificationtoken.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" userschema "honoka-chan/internal/schema/user" "honoka-chan/internal/session" + "net/http" "github.com/gin-gonic/gin" ) @@ -16,7 +17,7 @@ func setNotificationToken(ctx *gin.Context) { ss.Respond(userschema.SetNotificationTokenResp{ ResponseData: []any{}, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, }) } diff --git a/internal/handler/user/userinfo.go b/internal/handler/user/userinfo.go index fbefd0e..2b9950c 100644 --- a/internal/handler/user/userinfo.go +++ b/internal/handler/user/userinfo.go @@ -5,6 +5,7 @@ import ( "honoka-chan/internal/router" userschema "honoka-chan/internal/schema/user" "honoka-chan/internal/session" + "net/http" "time" "github.com/gin-gonic/gin" @@ -24,7 +25,7 @@ func userInfo(ctx *gin.Context) { ServerTimestamp: time.Now().Unix(), }, ReleaseInfo: []any{}, - StatusCode: 200, + StatusCode: http.StatusOK, } ss.Respond(userResp) diff --git a/internal/middleware/common.go b/internal/middleware/common.go index abe1ac0..abaa1bd 100644 --- a/internal/middleware/common.go +++ b/internal/middleware/common.go @@ -3,6 +3,7 @@ package middleware import ( "fmt" "honoka-chan/internal/session" + honokautils "honoka-chan/internal/utils" "net/http" "net/url" "strconv" @@ -31,7 +32,7 @@ func Common(ctx *gin.Context) { if ctx.Request.URL.Path != "/login/authkey" && ctx.Request.URL.Path != "/login/login" { if ss.UserPref.ForceRelogin { - ctx.AbortWithStatus(http.StatusNotFound) + honokautils.AbortMaintenanceJSON(ctx, http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.String())) return } } @@ -39,7 +40,7 @@ func Common(ctx *gin.Context) { authorize := ctx.GetHeader("Authorize") params, err := url.ParseQuery(authorize) if err != nil { - ctx.AbortWithStatus(http.StatusNotFound) + honokautils.AbortMaintenanceJSON(ctx, http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.String())) return } @@ -58,7 +59,7 @@ func Common(ctx *gin.Context) { ctx.Header("server_version", "20120129") ctx.Header("Server-Version", "97.4.6") ctx.Header("version_up", "0") - ctx.Header("status_code", "200") + ctx.Header("status_code", strconv.Itoa(http.StatusOK)) ctx.Next() } diff --git a/internal/middleware/recovery.go b/internal/middleware/recovery.go new file mode 100644 index 0000000..5de12a5 --- /dev/null +++ b/internal/middleware/recovery.go @@ -0,0 +1,40 @@ +package middleware + +import ( + "honoka-chan/internal/session" + honokautils "honoka-chan/internal/utils" + "log" + "net/http" + "runtime/debug" + + "github.com/gin-gonic/gin" +) + +func Recovery() gin.HandlerFunc { + return func(ctx *gin.Context) { + defer func() { + recovered := recover() + if recovered == nil { + return + } + + stack := debug.Stack() + log.Printf("panic serving %s %s: %v\n%s", ctx.Request.Method, ctx.Request.URL.String(), recovered, stack) + + 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) + }() + + ctx.Next() + } +} diff --git a/internal/router/router.go b/internal/router/router.go index d0af0d2..42baca0 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -2,9 +2,7 @@ package router import ( - "honoka-chan/internal/constant" - commonschema "honoka-chan/internal/schema/common" - "honoka-chan/internal/session" + honokautils "honoka-chan/internal/utils" "net/http" "os" "path/filepath" @@ -113,16 +111,12 @@ func SifRouter(r *gin.Engine) { }) notFoundHandler := func(ctx *gin.Context) { - ss := session.Attach(ctx) - defer ss.Finalize() + if !honokautils.IsMainPHPRequest(ctx.Request.URL.Path) { + ctx.AbortWithStatus(http.StatusNotFound) + return + } - ss.Respond(commonschema.ErrorResp{ - ResponseData: commonschema.ErrorData{ - ErrorCode: constant.ErrorCodeUnknown, - }, - ReleaseInfo: []any{}, - StatusCode: 600, - }) + honokautils.AbortMaintenanceJSON(ctx, http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.String())) } r.NoRoute(notFoundHandler) r.NoMethod(notFoundHandler) diff --git a/internal/session/session.go b/internal/session/session.go index f66795d..0b9b129 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" usermodel "honoka-chan/internal/model/user" + honokautils "honoka-chan/internal/utils" "honoka-chan/pkg/db" "honoka-chan/pkg/encrypt" "log" @@ -81,24 +82,19 @@ func (ss *Session) Finalize() { } ss.done = true - if ss.MainEng != nil { - ss.MainEng.Close() - ss.MainEng = nil - } - if ss.UserEng == nil { + ss.closeMainSession() return } if err := ss.UserEng.Commit(); err != nil { log.Println(err.Error()) - ss.UserEng.Close() - ss.UserEng = nil - ss.resp.writeJSON(500, gin.H{"error": err.Error()}) - ss.resp.abort() + ss.closeAllSessions(false) + ss.respondError(http.StatusInternalServerError, honokautils.NewInternalErrorContent(err)) return } + ss.closeMainSession() ss.UserEng.Close() ss.UserEng = nil } @@ -107,23 +103,25 @@ func (ss *Session) Abort(err error) { if ss.done { return } - ss.done = true - if ss.MainEng != nil { - ss.MainEng.Close() - ss.MainEng = nil - } - if ss.UserEng != nil { - ss.UserEng.Rollback() - ss.UserEng.Close() - ss.UserEng = nil - } + msg := ss.formatAbortMessage(err) + log.Println(msg) + ss.abortWithContent(http.StatusInternalServerError, honokautils.NewErrorContent("SessionAbort", msg)) +} - skip := 1 - if pc, _, _, ok := runtime.Caller(1); ok { +func (ss *Session) AbortWithStatus(status int, content any) { + if ss.done { + return + } + ss.abortWithContent(status, content) +} + +func (ss *Session) formatAbortMessage(err error) string { + skip := 2 + if pc, _, _, ok := runtime.Caller(2); ok { fn := runtime.FuncForPC(pc) if fn != nil && strings.HasSuffix(fn.Name(), ".(*Session).CheckErr") { - skip = 2 + skip = 3 } } loc := "unknown" @@ -135,11 +133,7 @@ func (ss *Session) Abort(err error) { } loc = fmt.Sprintf("%s:%d (%s)", file, line, funcName) } - msg := fmt.Sprintf("[%s] %s", loc, err.Error()) - log.Println(msg) - - ss.resp.writeJSON(500, gin.H{"error": msg}) - ss.resp.abort() + return fmt.Sprintf("[%s] %s", loc, err.Error()) } func (ss *Session) CheckErr(err error) bool { @@ -161,3 +155,33 @@ func (ss *Session) Respond(resp any) { ss.resp.setHeader("X-Message-Sign", base64.StdEncoding.EncodeToString(encrypt.RSASignSHA1(data))) ss.resp.writeBody(http.StatusOK, string(data)) } + +func (ss *Session) abortWithContent(status int, content any) { + ss.done = true + ss.closeAllSessions(true) + ss.respondError(status, content) +} + +func (ss *Session) respondError(status int, content any) { + honokautils.WriteMaintenanceJSON(ss.resp.setHeader, ss.resp.writeJSON, status, content) + ss.resp.abort() +} + +func (ss *Session) closeAllSessions(rollbackUser bool) { + ss.closeMainSession() + if ss.UserEng == nil { + return + } + if rollbackUser { + _ = ss.UserEng.Rollback() + } + ss.UserEng.Close() + ss.UserEng = nil +} + +func (ss *Session) closeMainSession() { + if ss.MainEng != nil { + ss.MainEng.Close() + ss.MainEng = nil + } +} diff --git a/internal/utils/error.go b/internal/utils/error.go index bca00f0..7f7192d 100644 --- a/internal/utils/error.go +++ b/internal/utils/error.go @@ -1,6 +1,15 @@ package honokautils -import "errors" +import ( + "errors" + "fmt" + "net/http" + "reflect" + "strconv" + "strings" + + "github.com/gin-gonic/gin" +) type UnimplementedError struct { Kind string @@ -35,3 +44,82 @@ func IsUnimplementedError(err error) bool { var target *UnimplementedError return err != nil && errors.As(err, &target) } + +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"` +} + +func IsMainPHPRequest(path string) bool { + return path == "/main.php" || strings.HasPrefix(path, "/main.php/") +} + +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)) + setHeader(maintenanceHeader, "1") + writeJSON(status, content) +} + +func AbortMaintenanceJSON(ctx *gin.Context, status int, content any) { + WriteMaintenanceJSON(ctx.Header, ctx.JSON, status, content) + ctx.Abort() +} + +func NewDetailContent(detail string) ErrorContent { + return ErrorContent{ + Detail: detail, + } +} + +func NewNotFoundContent(path string) ErrorContent { + return NewDetailContent(fmt.Sprintf("Endpoint not found: %s", path)) +} + +func NewInternalErrorContent(err error) ErrorContent { + return ErrorContent{ + Exception: exceptionName(err), + Message: err.Error(), + } +} + +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") +} diff --git a/main.go b/main.go index 0b5c879..9741aa7 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "honoka-chan/config" _ "honoka-chan/internal/handler" + "honoka-chan/internal/middleware" "honoka-chan/internal/router" "honoka-chan/internal/startup" "honoka-chan/pkg/db" @@ -48,6 +49,7 @@ func main() { "/v1/account/reportRole", }, })) + r.Use(middleware.Recovery()) // SIF router.SifRouter(r)