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:
2026-06-04 03:05:32 +08:00
parent 60677fe0dd
commit e61c07a9a3
53 changed files with 220 additions and 135 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ import (
)
func active(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
ss.Respond(ghomeschema.ActiveResp{
+1 -1
View File
@@ -13,7 +13,7 @@ import (
)
func initialize(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
initData := ghomeschema.InitializeData{
+1 -1
View File
@@ -33,7 +33,7 @@ const (
)
func login(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
data, err := ctx.GetRawData()
+1 -1
View File
@@ -15,7 +15,7 @@ import (
)
func loginAuto(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
data, err := ctx.GetRawData()
+1 -1
View File
@@ -11,7 +11,7 @@ import (
)
func reportRole(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
randKey, err := ss.Get3DESRandKey()
+1 -1
View File
@@ -10,7 +10,7 @@ import (
)
func getCode(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
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"}`
@@ -9,7 +9,7 @@ import (
)
func getProductList(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
getProductListData := ghomeschema.GetProductListData{
+1 -1
View File
@@ -17,7 +17,7 @@ import (
)
func handshake(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
data, err := ctx.GetRawData()
+1 -1
View File
@@ -9,7 +9,7 @@ import (
)
func loginArea(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
ss.Respond(ghomeschema.LoginAreaResp{
+1 -1
View File
@@ -13,7 +13,7 @@ import (
)
func publicKey(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
publicKeyCode := 0
+1 -1
View File
@@ -9,7 +9,7 @@ import (
)
func status(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
ss.Respond(ghomeschema.GuestStatusResp{
+1 -1
View File
@@ -9,7 +9,7 @@ import (
)
func agreement(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
ss.Respond(ghomeschema.AgreementResp{
+1 -1
View File
@@ -9,7 +9,7 @@ import (
)
func appReport(ctx *gin.Context) {
ss := session.New(ctx)
ss := session.Attach(ctx)
defer ss.Finalize()
ss.Respond(ghomeschema.AppReportResp{