草庐IT

go - 如何将参数传递给我的身份验证中间件以获取数据库访问权限

在我的AuthMw中间件中,我想进行数据库调用。我的数据库变量在main中初始化,我如何将它传递给我的中间件AuthMw?funcmain(){db,err:=gorm.Open("postgres",...)r:=mux.NewRouter()r.Handle("/ws",serveWebsocket(hub))r.Use(AuthMw)////...}//mainfuncAuthMw(nexthttp.Handler)http.Handler{returnhttp.HandlerFunc(func(whttp.ResponseWriter,r*http.Request){token

go - 如何将参数传递给我的身份验证中间件以获取数据库访问权限

在我的AuthMw中间件中,我想进行数据库调用。我的数据库变量在main中初始化,我如何将它传递给我的中间件AuthMw?funcmain(){db,err:=gorm.Open("postgres",...)r:=mux.NewRouter()r.Handle("/ws",serveWebsocket(hub))r.Use(AuthMw)////...}//mainfuncAuthMw(nexthttp.Handler)http.Handler{returnhttp.HandlerFunc(func(whttp.ResponseWriter,r*http.Request){token