forked from dash-ops/dash-ops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (54 loc) · 1.69 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 (
"encoding/json"
"fmt"
"log"
"net/http"
"time"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/dash-ops/dash-ops/pkg/aws"
"github.com/dash-ops/dash-ops/pkg/config"
"github.com/dash-ops/dash-ops/pkg/kubernetes"
"github.com/dash-ops/dash-ops/pkg/oauth2"
"github.com/dash-ops/dash-ops/pkg/spa"
)
func main() {
fileConfig := config.GetFileGlobalConfig()
dashConfig := config.GetGlobalConfig(fileConfig)
router := mux.NewRouter()
cors := handlers.CORS(
handlers.AllowedHeaders(dashConfig.Headers),
handlers.AllowedOrigins([]string{dashConfig.Origin}),
handlers.AllowCredentials(),
)
router.Use(cors)
api := router.PathPrefix("/api").Subrouter()
api.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(map[string]bool{"ok": true})
})
config.MakeConfigHandlers(api, dashConfig)
internal := api.PathPrefix("/v1").Subrouter()
if dashConfig.Plugins.Has("OAuth2") {
// ToDo transform into isolated plugins
oauth2.MakeOauthHandlers(api, internal, fileConfig)
}
if dashConfig.Plugins.Has("Kubernetes") {
// ToDo transform into isolated plugins
kubernetes.MakeKubernetesHandlers(internal, fileConfig)
}
if dashConfig.Plugins.Has("AWS") {
// ToDo transform into isolated plugins
aws.MakeAWSInstanceHandlers(internal, fileConfig)
}
spaHandler := spa.Handler{StaticPath: dashConfig.Front, IndexPath: "index.html"}
router.PathPrefix("/").Handler(spaHandler)
fmt.Println("DashOps server running!!")
srv := &http.Server{
Handler: router,
Addr: fmt.Sprintf(":%s", dashConfig.Port),
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
log.Fatal(srv.ListenAndServe())
}