-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
72 lines (53 loc) · 1.54 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
package main
import (
"net/http"
"os"
"github.com/go-chi/jwtauth"
"github.com/mangodev-io/mango/api/cmd/api/config"
"github.com/algorand/go-algorand-sdk/client/algod"
"github.com/sirupsen/logrus"
)
func main() {
logger := logrus.New()
logrus.SetFormatter(&logrus.JSONFormatter{})
logrus.SetOutput(os.Stdout)
logrus.SetLevel(logrus.TraceLevel)
retCode := 0
// Exit with return code
defer func() {
logger.Exit(retCode)
os.Exit(retCode)
}()
// Catch panics
defer func() {
if err := recover(); err != nil {
logger.Panic(err.(string))
retCode = 1
return
}
}()
// Load Configuration
config, err := config.New()
if err != nil {
logger.WithError(err).Panic("Missing configuration")
}
logger.Info("Loaded configuration...")
// Setup Algod Client
var headers []*algod.Header
headers = append(headers, &algod.Header{"X-API-Key", config.PSToken})
testnetAlgodClient, err := algod.MakeClientWithHeaders(config.TestnetAlgodAddress, "", headers)
if err != nil {
logger.WithError(err).Panic("failed to make algod client")
}
mainnetAlgodClient, err := algod.MakeClientWithHeaders(config.MainnetAlgodAddress, "", headers)
if err != nil {
logger.WithError(err).Panic("failed to make algod client")
}
// Setup JWT Auth
tokenAuth := jwtauth.New("HS256", []byte(config.TokenAuthPassword), nil)
// Setup Router
routerService := NewRouterService(logger, &testnetAlgodClient, &mainnetAlgodClient, tokenAuth)
// Serve
logger.Info("Starting server on port 5000")
logger.Fatal(http.ListenAndServe(":5000", routerService))
}