Created
July 1, 2015 04:33
Revisions
-
jonathaningram created this gist
Jul 1, 2015 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ package web func contactHandler( res http.ResponseWriter, req *http.Request, csrf csrf.TokenManager, nodeRepository node.Repository, ) { } This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ package web import ( "github.com/codegangsta/negroni" "github.com/goincremental/negroni-sessions" "github.com/goincremental/negroni-sessions/cookiestore" "github.com/gorilla/pat" ) // init because this is app engine func init() { // create services store := cookiestore.New([]byte(appConfig.Secret)) templateEngine := template.NewEngine() userRepository := user.NewCachingRepository(user.NewMemoryRepository()) nodeRepository := node.NewCachingRepository(node.NewDatastoreRepository()) router := pat.New() router.NewRoute().Methods("HEAD", "GET").PathPrefix("/contact").Handler(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { session := sessions.GetSession(req) contactHandler( res, req, csrf.NewTokenManager(session), nodeRepository, ) // could use some sort of DI-type container too but haven't had a need yet contactHandler( res, req, container.Get("node_repository"), // the container can determine what "node_repository" implementation gets returned, maybe it can even lazy-create it ) })) n := negroni.New() n.UseHandler(router) }