-
Notifications
You must be signed in to change notification settings - Fork 0
/
karts.go
35 lines (28 loc) · 865 Bytes
/
karts.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
package karts
import (
"fmt"
"os"
"log"
"net/http"
"github.com/julienschmidt/httprouter"
"github.com/firedrake969/karts/staticfiles"
"github.com/firedrake969/karts/views"
)
// This runs everything. Pass it a mapping of strings (url routes)
// to views.View structs and it will serve both your views and
// staticfiles.
func RunKarts(routes map[string]views.View) {
fmt.Println("Starting...")
router := httprouter.New()
staticlist := staticfiles.GetStaticfiles()
for staticfile := range staticlist {
router.GET(staticlist[staticfile].Servedpath, staticlist[staticfile].Serve)
}
for k := range routes {
route := routes[k]
router.GET(k, route.HandleGet)
router.POST(k, route.HandlePost)
}
port := os.Args[1]
log.Fatal(http.ListenAndServe(":" + port, router))
}