/
server.go
58 lines (39 loc) · 908 Bytes
/
server.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"github.com/go-martini/martini"
"github.com/fzzy/radix/redis"
"time"
)
func errHndlr(err error) {
if err != nil {
}
}
func main() {
m := martini.Classic()
c, err := redis.DialTimeout("tcp", "127.0.0.1:6379", time.Duration(10)*time.Second)
errHndlr(err)
defer c.Close()
m.Group("/listings", func(r martini.Router) {
r.Get("", GetListingsIndex)
r.Get("/:id", GetListing)
r.Post("/new", NewListing)
r.Put("/update/:id", UpdateListing)
r.Delete("/delete/:id", DeleteListing)
})
m.Run()
}
func GetListingsIndex(params martini.Params) {
// return all listings
}
func GetListing(params martini.Params) {
// return single listing
}
func NewListing(params martini.Params) {
// create new listing
}
func UpdateListing(params martini.Params) {
// update a listing
}
func DeleteListing(params martini.Params) {
// delete a listing
}