-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
75 lines (62 loc) · 1.79 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
66
67
68
69
70
71
72
73
74
75
package main
import (
"net/http"
"github.com/gorilla/mux"
"github.com/qa-kit/awesome-grid/cleaner"
"github.com/qa-kit/awesome-grid/cluster"
configPkg "github.com/qa-kit/awesome-grid/config"
"github.com/qa-kit/awesome-grid/creator"
"github.com/qa-kit/awesome-grid/lookup"
poolPkg "github.com/qa-kit/awesome-grid/pool"
"github.com/qa-kit/awesome-grid/proxyhandler"
"github.com/qa-kit/awesome-grid/session"
"github.com/qa-kit/awesome-grid/transport"
logger "github.com/sirupsen/logrus"
)
const (
// ConfigPath path to config
ConfigPath = "config.json"
)
func main() {
logger.SetFormatter(&logger.TextFormatter{
FullTimestamp: true,
})
var (
r = mux.NewRouter()
config = &configPkg.Config{}
pool = &poolPkg.Pool{}
cluster = &cluster.Kubernetes{
Config: config,
}
sessionGrabber = session.New(pool, config)
newSessionHandler = proxyhandler.New(
creator.New(config, cluster, pool, &cleaner.Cleaner{}, http.Get),
transport.New(sessionGrabber.Grab, http.DefaultTransport.RoundTrip),
)
existSessionHandler = proxyhandler.New(
lookup.New(pool, config),
nil,
)
)
// New session handler
r.HandleFunc("/wd/hub/session", newSessionHandler.Handle)
// Healthcheck
r.HandleFunc("/status/", func(res http.ResponseWriter, request *http.Request) {
res.Header().Set("Content-Type", "application/json")
res.Write([]byte("{\"status\":\"ok\"}"))
})
// Existing session handler
r.PathPrefix("/").Handler(http.HandlerFunc(existSessionHandler.Handle))
http.Handle("/", r)
// Reading configs
if err := config.Read(ConfigPath); err != nil {
logger.Fatal(err.Error())
}
// Creating clients
if err := cluster.CreateClient(); err != nil {
logger.Fatal(err.Error())
}
if err := http.ListenAndServe(config.Listen, nil); err != nil {
logger.Fatal(err.Error())
}
}