-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.go
63 lines (50 loc) · 2.63 KB
/
application.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
package main
import (
"fmt"
"net/http"
"git.amabanana.com/plancks-cloud/pc-go-daemon/model"
"git.amabanana.com/plancks-cloud/pc-go-daemon/api"
"git.amabanana.com/plancks-cloud/pc-go-daemon/controller/community"
"git.amabanana.com/plancks-cloud/pc-go-daemon/controller/health"
"git.amabanana.com/plancks-cloud/pc-go-daemon/controller/remote"
"git.amabanana.com/plancks-cloud/pc-go-daemon/mem"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
)
const port = 8080
func main() {
initAll()
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/api/createContract", api.CORSHandler(api.CreateContract)).Methods("POST", "OPTIONS")
router.HandleFunc("/api/updateContract", api.CORSHandler(api.UpdateContract)).Methods("POST", "OPTIONS")
router.HandleFunc("/api/createCancelContract", api.CORSHandler(api.CreateCancelContract)).Methods("POST", "OPTIONS")
// router.HandleFunc("/api/createWallet", api.CORSHandler(api.CreateWallet)).Methods("POST", "OPTIONS")
router.HandleFunc("/api/dockerListServices", api.CORSHandler(api.DockerListServices)).Methods("GET", "OPTIONS") //ADD JSON RETURN
router.HandleFunc("/api/dockerListRunningServices", api.CORSHandler(api.DockerListRunningServices)).Methods("GET", "OPTIONS") //ADD JSON RETURN
router.HandleFunc("/api/forceSync", api.CORSHandler(api.ForceSync)).Methods("GET", "OPTIONS")
router.HandleFunc("/api/getContract", api.CORSHandler(api.GetContract)).Methods("GET", "OPTIONS")
router.HandleFunc("/api/ping", api.CORSHandler(api.Ping)).Methods("GET", "OPTIONS")
router.HandleFunc("/api/setCurrentWallet", api.CORSHandler(api.SetCurrentWallet)).Methods("POST", "OPTIONS")
router.HandleFunc("/api/getOneContract", api.CORSHandler(api.GetOneContract)).Methods("GET", "OPTIONS")
router.HandleFunc("/api/getContractResult", api.CORSHandler(api.GetContractResult)).Methods("GET", "OPTIONS")
router.HandleFunc("/api/getServiceStateResult", api.CORSHandler(api.GetServiceStateResult)).Methods("GET", "OPTIONS")
router.HandleFunc("/api/🦖", api.CORSHandler(api.CheckStatus)).Methods("GET", "OPTIONS")
router.HandleFunc("/api/generate-key-pair", api.CORSHandler(api.GetPrivatePublicKey)).Methods("GET", "OPTIONS")
log.Fatal(http.ListenAndServe(fmt.Sprint(":", port), router))
log.Info(fmt.Sprintf("READY: Listening [:%v]", port))
}
func initAll() {
if model.GetEnvLogFormat() == "json" {
log.SetFormatter(&log.JSONFormatter{})
} else {
log.SetFormatter(&log.TextFormatter{})
}
// log.SetLevel(log.ErrorLevel)
log.Info("Starting")
mem.Init()
model.InitRepo()
remote.Init()
remote.ScheduleRemoteSync()
community.ScheduleCommunityActivities()
health.ScheduleHealthCheck()
}