-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
45 lines (33 loc) · 1.08 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"github.com/pilu/traffic"
)
var router *traffic.Router
func init() {
router = traffic.New()
router.Get("/", RootHandler)
// match (width)x(height) format
// we cannot choose which character set the named routes can take
// they only stop matching on / # ? ( ) . \
// we should be able to do something like
// (:width=[\d+])(x(:height=[\d+]))?
// or something even simplier like
// (:width=:digits)(x(:height=:digits))(.(:format=json|xml|atom))
router.Get(`/(?P<width>\d+)(x(?P<height>\d+)?)?/?`, ImageHandler).
AddBeforeFilter(RequireValidImageParameters).
AddBeforeFilter(GenerateImageCache)
router.Get(`/:width/?(:height)?/?`, ImageHandler).
AddBeforeFilter(RequireValidImageParameters).
AddBeforeFilter(GenerateImageCache)
// Executed before all handlers
router.AddBeforeFilter(PoweredByHandler)
// Custom not found handler
router.NotFoundHandler = NotFoundHandler
// if not in development, add the static handler
if traffic.Env() == "production" {
router.Use(traffic.NewStaticMiddleware(traffic.PublicPath()))
}
}
func main() {
router.Run()
}