Implement a new manager help you port the app to different database. This can be done by these step:
###Step 1, 2 Quite simple, but maybe a lot of work. You can find some test in https://github.com/kidstuff/auth-mongo-mngr/ to make sure your Manager and Configurator work.
###Step 3 Implement an http.Handler and call auth.BasicMngrHandler in ServeHTTP method. For example, the auth-mongo-mngr does:
type mongoMngrHandler struct { db *mgo.Database fn auth.HandleFunc cond auth.Condition } func (h mongoMngrHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { cloneDB := h.db.Session.Clone().DB(h.db.Name) defer cloneDB.Session.Close() ctx := auth.AuthContext{} ctx.Auth = NewMgoManager(cloneDB) ctx.Settings = NewMgoConfigMngr(cloneDB) auth.BasicMngrHandler(&ctx, rw, req, &h.cond, h.fn) }
Then "overide" the auth.HANDLER_REGISTER in your initial function.
func Initial(db *mgo.Database) { auth.HANDLER_REGISTER = func(fn auth.HandleFunc, owner bool, pri []string) http.Handler { return mongoMngrHandler{ db: db, fn: fn, cond: auth.Condition{ RequiredPri: pri, Owner: owner, }, } } }
The auth-mongo-mngr require that developer must explicit call Initial function to choose which database to use in their application.
There was an error while loading. Please reload this page.