基本逻辑完成
This commit is contained in:
25
internal/middleware/json.go
Normal file
25
internal/middleware/json.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"game-driver/internal/schema"
|
||||
"game-driver/leaf"
|
||||
"log"
|
||||
)
|
||||
|
||||
type JSONKey string
|
||||
|
||||
const PayloadJSONKey JSONKey = "payload_json"
|
||||
|
||||
// PayloadJSON 解析报文
|
||||
func PayloadJSON() leaf.HandlerFunc {
|
||||
return func(c *leaf.Context) {
|
||||
pm := &schema.PlayModal{}
|
||||
err := json.Unmarshal(c.Payload, pm)
|
||||
if err != nil {
|
||||
log.Panicf("报文解析错误: %v\n", err)
|
||||
}
|
||||
leaf.WithValue[*schema.PlayModal](c, PayloadJSONKey, pm)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user