-
-
Save alehano/10955835 to your computer and use it in GitHub Desktop.
Revisions
-
alehano revised this gist
Apr 17, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 @@ -24,7 +24,7 @@ func DB() martini.Handler { // ? c.Next() s.Close() } } -
alehano revised this gist
Apr 17, 2014 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -21,6 +21,10 @@ func DB() martini.Handler { return func(c martini.Context) { s := session.Clone() c.Map(s.DB("advent")) // ? c.Next() c.Close() } } -
codegangsta renamed this gist
Dec 8, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
codegangsta created this gist
Dec 8, 2013 .There are no files selected for viewing
This file contains hidden or 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,48 @@ package main import ( "github.com/codegangsta/martini" "github.com/codegangsta/martini-contrib/binding" "github.com/codegangsta/martini-contrib/render" "labix.org/v2/mgo" ) type Wish struct { Name string `form:"name"` Description string `form:"description"` } func DB() martini.Handler { session, err := mgo.Dial("mongodb://localhost") if err != nil { panic(err) } return func(c martini.Context) { s := session.Clone() c.Map(s.DB("advent")) } } func GetAll(db *mgo.Database) []Wish { var wishlist []Wish db.C("wishes").Find(nil).All(&wishlist) return wishlist } func main() { m := martini.Classic() m.Use(render.Renderer()) m.Use(DB()) m.Get("/wishes", func(r render.Render, db *mgo.Database) { r.HTML(200, "list", GetAll(db)) }) m.Post("/wishes", binding.Form(Wish{}), func(r render.Render, db *mgo.Database, wish Wish) { db.C("wishes").Insert(wish) r.HTML(200, "list", GetAll(db)) }) m.Run() }