-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (60 loc) · 1.64 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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/signal"
"runtime"
"strings"
"syscall"
"github.com/SwingbyProtocol/node-agent/config"
"github.com/SwingbyProtocol/node-agent/types"
"github.com/SwingbyProtocol/tx-indexer/api"
"github.com/ant0ine/go-json-rest/rest"
log "github.com/sirupsen/logrus"
)
func init() {
log.SetReportCaller(true)
log.SetFormatter(&log.TextFormatter{
ForceColors: true,
FullTimestamp: true,
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
s := strings.Split(f.Function, ".")
funcname := s[len(s)-1]
//_, filename := path.Split(f.File)
paddedFuncname := fmt.Sprintf(" %-20v", funcname+"()")
//paddedFilename := fmt.Sprintf("%17v", filename)
return paddedFuncname, ""
},
})
log.SetOutput(os.Stdout)
}
func main() {
conf, err := config.NewDefaultConfig()
if err != nil {
log.Fatal(err)
}
apiConfig := &api.APIConfig{
ListenREST: conf.RESTConfig.ListenAddr,
ListenWS: conf.WSConfig.ListenAddr,
Actions: []*api.Action{},
}
getStatus := func(w rest.ResponseWriter, r *rest.Request) {
file, _ := ioutil.ReadFile("./data/node_status.json")
data := types.NodeStatus{}
_ = json.Unmarshal([]byte(file), &data)
w.WriteJson(data)
}
getStatusAction := api.NewGet("/api/v1/status", getStatus)
apiConfig.Actions = append(apiConfig.Actions, getStatusAction)
// Create api server
apiServer := api.NewAPI(apiConfig)
// Start server
apiServer.Start()
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGSTOP)
signal := <-c
// Backup operation
log.Info(signal)
}