Hey Mat
Benjamin Hammer Nørgaard
4

Thanks.

In fact, it’s better to not hide dependencies inside Context. So if you need a MongoDB session to send into the handler, use a Server struct and access the dependency directly (and explictly) from that:

type Server struct {
db *mgo.Session
}

func (s *Server) handleSomething(w http.ResponseWriter, r *http.Request) {
db := s.db.Copy()
defer db.Close()
// TODO: use db
}