-
Notifications
You must be signed in to change notification settings - Fork 3
/
mapwrap.go
53 lines (42 loc) · 1.13 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
53
package main
import(
"net/http"
"log"
"fmt"
"os"
"flag"
)
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)
}
err = http.ListenAndServe(":" + GetConfig().Port, nil)
if err != nil {
fmt.Printf("Unable to start: %v", err)
}
}