-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.go
More file actions
45 lines (39 loc) · 948 Bytes
/
server.go
File metadata and controls
45 lines (39 loc) · 948 Bytes
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
39
40
41
42
43
44
45
package main
import (
_ "fmt"
"github.com/go-martini/martini"
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
"github.com/martini-contrib/render"
"github.com/tangosource/martini_example/controllers"
)
func SetupDB() gorm.DB {
db, err := gorm.Open("postgres", "dbname=martini_example sslmode=disable")
db.LogMode(true)
PanicIf(err)
return db
}
func PanicIf(err error) {
if err != nil {
panic(err)
}
}
func main() {
m := martini.Classic()
m.Map(SetupDB())
m.Use(render.Renderer(render.Options{
Directory: "views",
Layout: "layouts/layout",
Charset: "UTF-8",
IndentJSON: true,
IndentXML: true,
}))
m.Get("/persons/new", persons.NewPerson)
m.Get("/persons/:id/edit", persons.EditPerson)
m.Get("/persons/:id", persons.ShowPerson)
m.Post("/persons/:id", persons.UpdatePerson)
m.Get("/persons/:id/delete", persons.DeletePerson)
m.Post("/persons", persons.CreatePerson)
m.Get("/", persons.Index)
m.Run()
}