-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcase_test.go
53 lines (44 loc) · 1.22 KB
/
case_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
// Package makross is a high productive and modular web framework in Golang.
package makross_test
import (
"log"
"github.com/insionng/makross"
"github.com/insionng/makross/access"
"github.com/insionng/makross/content"
"github.com/insionng/makross/fault"
"github.com/insionng/makross/file"
"github.com/insionng/makross/logger"
"github.com/insionng/makross/slash"
)
func Case() {
m := makross.New()
m.Use(
// all these handlers are shared by every route
access.Logger(log.Printf),
logger.Logger(),
slash.RemoveTrailingSlash(),
fault.Recovery(log.Printf),
)
// serve RESTful APIs
api := m.Group("/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 *makross.Context) error {
return c.Write("user list")
})
api.Post("/users", func(c *makross.Context) error {
return c.Write("create a new user")
})
api.Put(`/users/<id:\d+>`, func(c *makross.Context) error {
return c.Write("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(8888)
}