-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
56 lines (46 loc) · 1.4 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
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/stakedotlink/token-supply-api/app"
"github.com/stakedotlink/token-supply-api/app/uncirculating"
)
func main() {
var configPath string
flag.StringVar(&configPath, "config", "config.yaml", "config file path")
a, err := app.NewTokenSupply(configPath, &uncirculating.ExcludedAddresses{}, &uncirculating.VestedTokens{}, &uncirculating.LockedTokens{})
if err != nil {
log.Fatal(err)
}
if err := a.Start(); err != nil {
log.Fatal(err)
}
http.HandleFunc("/total", totalSupplyHandler(a))
http.HandleFunc("/circulating", circulatingSupplyHandler(a))
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
log.Printf("Starting Token Supply API on port %d\n", a.Config.Port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", a.Config.Port), nil))
}()
<-sigs
a.Stop()
log.Printf("Stopped Token Supply API")
}
func totalSupplyHandler(a *app.TokenSupply) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
_, _ = fmt.Fprintln(w, a.TotalSupply().String())
}
}
func circulatingSupplyHandler(a *app.TokenSupply) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
_, _ = fmt.Fprintln(w, a.CirculatingSupply().String())
}
}