|
123456789101112131415161718192021222324252627282930 |
- package mw
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/svc"
- "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()
- }
|