-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.go
More file actions
42 lines (32 loc) · 933 Bytes
/
server.go
File metadata and controls
42 lines (32 loc) · 933 Bytes
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
package main
import (
"net/http"
"text/template"
"github.com/codegangsta/negroni"
"github.com/gorilla/mux"
)
// NewServer configures and returns a Server.
func NewServer() *negroni.Negroni {
n := negroni.Classic()
mx := mux.NewRouter()
initRoutes(mx)
n.UseHandler(mx)
return n
}
func initRoutes(mx *mux.Router) {
mx.PathPrefix("/images/").Handler(http.StripPrefix("/images/", http.FileServer(http.Dir("./assets/images/"))))
mx.PathPrefix("/css/").Handler(http.StripPrefix("/css/", http.FileServer(http.Dir("./assets/css/"))))
mx.HandleFunc("/", homeHandler)
}
type sampleContent struct {
ID string `json:"id"`
Content string `json:"content"`
}
var t *template.Template
func init() {
t = template.Must(template.ParseFiles("assets/templates/index.html"))
}
func homeHandler(w http.ResponseWriter, req *http.Request) {
data := sampleContent{ID: "8675309", Content: "Hello from Go!"}
t.Execute(w, data)
}