-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
38 lines (30 loc) · 837 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"github.com/madhums/go-martini-mgo-demo/Godeps/_workspace/src/github.com/go-martini/martini"
"github.com/madhums/go-martini-mgo-demo/Godeps/_workspace/src/github.com/martini-contrib/binding"
"github.com/madhums/go-martini-mgo-demo/handlers/articles"
"github.com/madhums/go-martini-mgo-demo/middlewares"
"github.com/madhums/go-martini-mgo-demo/models"
)
/**
* Main
*
* - use middlewares
* - define routes
* - listen and serve
*/
func main() {
// Initialize
m := martini.Classic()
// Connect to mongo
m.Use(middlewares.Connect())
// Templating support
m.Use(middlewares.Templates())
// Routes
m.Get("/", articles.List)
m.Get("/new", articles.AddEdit)
m.Post("/articles", binding.Form(models.Article{}), articles.Add)
m.Get("/articles/:_id", articles.Show)
// Start listening
m.Run()
}