-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (47 loc) · 1.04 KB
/
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
49
50
51
52
53
54
55
56
57
package main
import (
"flag"
"fmt"
"log"
"net/http"
)
var (
cfg config
version = "master"
build = "0000-00-00 00:00:00"
)
func init() {
// set default values in config
cfg.BindIP = "0.0.0.0"
cfg.BindPort = "8080"
cfg.APIURI = "/api"
cfg.Projects = make(map[string]project)
}
func main() {
// logs debug info
log.SetFlags(log.LstdFlags | log.Llongfile)
// parse flags
cfgFilePath := flag.String("config", "./config.yml", "config file")
v := flag.Bool("version", false, "print version")
flag.Parse()
// handle flags
if *v == true {
// version request
fmt.Printf("version: %s, build: %s\n", version, build)
} else {
// read config
err := readConfig(cfgFilePath)
if err != nil {
log.Fatalln(err)
}
// debug config print
// fmt.Printf("config: #%v\n", cfg)
http.Handle("/img/", http.StripPrefix("/img/", http.FileServer(http.Dir("img"))))
// run rest API
http.HandleFunc(cfg.APIURI+"/", postHandler)
err = http.ListenAndServe(cfg.BindIP+":"+cfg.BindPort, nil)
if err != nil {
log.Println(err)
}
}
}