-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
33 lines (27 loc) · 816 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
package main
import (
"log"
"github.com/albrow/negroni-json-recovery"
"github.com/albrow/people/controllers"
"github.com/albrow/people/models"
"github.com/codegangsta/negroni"
"github.com/gorilla/mux"
)
func main() {
defer func() {
if err := models.ClosePool(); err != nil {
log.Fatal(err)
}
}()
router := mux.NewRouter()
people := controllers.People{}
router.HandleFunc("/people", people.Index).Methods("GET")
router.HandleFunc("/people", people.Create).Methods("POST")
router.HandleFunc("/people/{id}", people.Show).Methods("GET")
router.HandleFunc("/people/{id}", people.Update).Methods("PUT", "PATCH")
router.HandleFunc("/people/{id}", people.Delete).Methods("DELETE")
n := negroni.New(negroni.NewLogger())
n.Use(recovery.JSONRecovery(true))
n.UseHandler(router)
n.Run(":3000")
}