/
main.go
48 lines (39 loc) · 955 Bytes
/
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
46
47
48
package main
import (
"fmt"
"github.com/hypebeast/gojistatic"
"github.com/yosssi/ace"
"github.com/zenazn/goji"
"github.com/zenazn/goji/web"
"net/http"
)
// Ace Template Engine
// https://github.com/yosssi/ace/blob/master/documentation/getting-started.md
func hello(c web.C, w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", c.URLParams["name"])
}
func root(c web.C, w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("index", "", nil)
if err != nil {
panic(err)
}
data := map[string]interface{}{"Title": "Kanban"}
err = tpl.Execute(w, data)
if err != nil {
panic(err)
}
}
// Route configures routing. it is also used in test-code
func Route(m *web.Mux) {
m.Get("/hello/:name", hello)
m.Get("/", root)
}
func main() {
// setup static
goji.Use(gojistatic.Static("public",
gojistatic.StaticOptions{SkipLogging: true}))
// app routing
Route(goji.DefaultMux)
// start server
goji.Serve()
}