/
main.go
65 lines (53 loc) · 1.6 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
58
59
60
61
62
63
64
65
package main
import (
"flag"
"net/http"
"strings"
"github.com/crackcomm/convey-actions/api"
"github.com/crackcomm/convey-actions/executor"
"github.com/crackcomm/go-actions/core"
"github.com/golang/glog"
_ "github.com/crackcomm/go-actions/source/file"
_ "github.com/crackcomm/go-actions/source/http"
_ "github.com/crackcomm/go-core"
)
var (
listenaddr = "127.0.0.1:8080"
dashboard = "convey-dashboard"
sources = "actions"
tests = "tests"
watch = true
)
func init() {
flag.StringVar(&listenaddr, "listen", listenaddr, "HTTP Listening address")
flag.StringVar(&dashboard, "dashboard", dashboard, "Dashboard directory")
flag.StringVar(&sources, "sources", sources, "Actions sources (comma separated)")
flag.StringVar(&tests, "tests", tests, "Tests directory")
flag.BoolVar(&watch, "watch", watch, "Watch for changes in tests")
}
func main() {
defer glog.Flush()
flag.Set("logtostderr", "true")
flag.Set("v", "2")
flag.Parse()
// Add actions sources
for _, source := range strings.Split(sources, ",") {
core.Source(source)
}
// Executor
ex := executor.New(tests)
// API
http.Handle("/watch", api.WatchHandler{Executor: ex})
http.Handle("/execute", api.ExecuteHandler{Executor: ex})
http.Handle("/status/poll", api.PollHandler{Executor: ex})
http.Handle("/status", api.StatusHandler{Executor: ex})
http.Handle("/latest", api.LatestHandler{Executor: ex})
// Dashboard
http.Handle("/", http.FileServer(http.Dir(dashboard)))
if watch {
go ex.Watch()
}
// Start listening
glog.Infof("Listening on address %s\n", listenaddr)
glog.Fatal(http.ListenAndServe(listenaddr, nil))
}