forked from smacfarlane/mapwrap-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapwrap.go
52 lines (42 loc) · 1.19 KB
/
mapwrap.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
package main
import (
"flag"
"fmt"
"log"
"net/http"
)
var configFile string
var mapDirectory string
func init() {
const (
defaultConfig = "mapwrap.json"
configUsage = "the path to the mapwrap file"
defaultMapDir = "maps"
mapDirUsage = "the path to map files"
)
flag.StringVar(&configFile, "config", defaultConfig, configUsage)
flag.StringVar(&configFile, "c", defaultConfig, configUsage+" (shorthand)")
flag.StringVar(&mapDirectory, "maps", defaultMapDir, mapDirUsage)
flag.StringVar(&mapDirectory, "m", defaultMapDir, mapDirUsage)
loadConfig()
}
func main() {
flag.Parse()
// logFile, err := os.OpenFile("mapwrap.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
// if err != nil {
// log.Fatalf("Error opening file: %v", err)
// }
// defer logFile.Close()
// log.SetOutput(logFile)
// //Don't prefix the time in these logs
// log.SetFlags(0)
for _, m := range GetConfig().Maps {
path := fmt.Sprintf("%s", m.UrlPath())
http.HandleFunc(path, m.serveMap)
}
log.Printf("[INFO] Starting on :%s", GetConfig().Port)
err := http.ListenAndServe(":"+GetConfig().Port, nil)
if err != nil {
fmt.Printf("Unable to start: %v", err)
}
}