package mw import ( "applet/app/e" "applet/app/svc" db "code.fnuoos.com/zhimeng/model.git/src" "errors" "fmt" "github.com/gin-gonic/gin" ) // DB is 中间件 用来检查master_id是否有对应的数据库engine func DB(c *gin.Context) { fmt.Println(c.Request.Header) masterID := svc.GetMasterId(c) fmt.Println("master_id", masterID) if masterID == "" { e.OutErr(c, e.ERR_MASTER_ID, errors.New("not found master_id")) return } _, ok := db.DBs[masterID] if !ok { e.OutErr(c, e.ERR_MASTER_ID, errors.New("not found master_id in DBs")) return } fmt.Println("master_id", masterID) c.Set("mid", masterID) c.Next() }