Reduce handler request boilerplate
- Add session.Attach to reuse per-request sessions across middleware and ghome handlers - Make Session finalize/abort paths idempotent to avoid duplicate commit or rollback work - Move request_data parsing helper to internal/utils - Expand ParseRequestData usage across api, download, unit, live, multiunit, and subscenario handlers - Extract download package metadata into internal/handler/download/types.go - Return explicit errors from selected session lookup helpers and update callers - Make api action handlers return errors directly instead of calling ss.CheckErr in nested layers Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"honoka-chan/internal/router"
|
||||
liveschema "honoka-chan/internal/schema/live"
|
||||
"honoka-chan/internal/session"
|
||||
honokautils "honoka-chan/internal/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
"math"
|
||||
"strconv"
|
||||
@@ -20,7 +21,7 @@ func play(ctx *gin.Context) {
|
||||
defer ss.Finalize()
|
||||
|
||||
playReq := liveschema.PlayReq{}
|
||||
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &playReq)
|
||||
err := honokautils.ParseRequestData(ctx, &playReq)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"honoka-chan/internal/router"
|
||||
liveschema "honoka-chan/internal/schema/live"
|
||||
"honoka-chan/internal/session"
|
||||
honokautils "honoka-chan/internal/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -20,7 +21,7 @@ func preciseScore(ctx *gin.Context) {
|
||||
defer ss.Finalize()
|
||||
|
||||
playScoreReq := liveschema.PlayScoreReq{}
|
||||
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &playScoreReq)
|
||||
err := honokautils.ParseRequestData(ctx, &playScoreReq)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package live
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"honoka-chan/internal/middleware"
|
||||
usermodel "honoka-chan/internal/model/user"
|
||||
"honoka-chan/internal/router"
|
||||
liveschema "honoka-chan/internal/schema/live"
|
||||
"honoka-chan/internal/session"
|
||||
honokautils "honoka-chan/internal/utils"
|
||||
"honoka-chan/pkg/utils"
|
||||
"time"
|
||||
|
||||
@@ -21,7 +21,7 @@ func reward(ctx *gin.Context) {
|
||||
}()
|
||||
|
||||
playRewardReq := liveschema.RewardReq{}
|
||||
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &playRewardReq)
|
||||
err := honokautils.ParseRequestData(ctx, &playRewardReq)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user