-
Notifications
You must be signed in to change notification settings - Fork 2
/
macross_test.go
59 lines (52 loc) · 1.25 KB
/
macross_test.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
53
54
55
56
57
58
59
package macross_test
import (
"github.com/insionng/macross"
"github.com/insionng/macross/access"
"log"
/*
"github.com/insionng/macross/content"
"github.com/insionng/macross/fault"
"github.com/insionng/macross/file"
"github.com/insionng/macross/slash"
*/)
func MacrossTest() {
m := macross.New()
m.Use(
// all these handlers are shared by every route
access.Logger(log.Printf),
)
/*
m.Use(
// all these handlers are shared by every route
access.Logger(log.Printf),
slash.Remover(http.StatusMovedPermanently),
fault.Recovery(log.Printf),
)
*/
// serve RESTful APIs
api := m.Group("/v1/api")
/*
api.Use(
// these handlers are shared by the routes in the api group only
content.TypeNegotiator(content.JSON, content.XML),
)
*/
api.Get("/users", func(c *macross.Context) error {
return c.Data("user list")
})
api.Post("/users", func(c *macross.Context) error {
return c.Data("create a new user")
})
api.Put(`/users/<id:\d+>`, func(c *macross.Context) error {
return c.Data("update user " + c.Param("id").String())
})
/*
// serve index file
m.Get("/", file.Content("ui/index.html"))
// serve files under the "ui" subdirectory
m.Get("/*", file.Server(file.PathMap{
"/": "/ui/",
}))
*/
m.Listen(":9000")
}