forked from QLeelulu/goku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.go
62 lines (56 loc) · 1.51 KB
/
simple.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
60
61
62
package main
import (
//"os"
"github.com/QLeelulu/goku"
"log"
"path"
"runtime"
"time"
)
// routes
var routes []*goku.Route = []*goku.Route{
// static file route
&goku.Route{
Name: "static",
IsStatic: true,
Pattern: "/static/(.*)",
},
// default controller and action route
&goku.Route{
Name: "default",
Pattern: "/{controller}/{action}/{id}",
Default: map[string]string{"controller": "home", "action": "index", "id": "0"},
Constraint: map[string]string{"id": "\\d+"},
},
}
// server config
var config *goku.ServerConfig = &goku.ServerConfig{
Addr: ":8888",
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
//RootDir: os.Getwd(),
StaticPath: "static",
ViewPath: "views",
LogLevel: goku.LOG_LEVEL_LOG,
Debug: true,
}
func init() {
/**
* Controller & Action
*/
goku.Controller("home").
//Filters(new(TestControllerFilter)). // this filter is fot controller(all the actions)
Get("index", func(ctx *goku.HttpContext) goku.ActionResulter {
return ctx.Html("Hello World")
})
// project root dir
_, filename, _, _ := runtime.Caller(1)
config.RootDir = path.Dir(filename)
}
func main() {
rt := &goku.RouteTable{Routes: routes}
s := goku.CreateServer(rt, nil, config)
goku.Logger().Logln("Server start on", s.Addr)
log.Fatal(s.ListenAndServe())
}