-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (48 loc) · 1.38 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
package main
import (
"flag"
"fmt"
"log"
"net/http"
"strconv"
"time"
"github.com/btcsuite/btcd/rpcclient"
)
var verbose bool
func main() {
flag.BoolVar(&verbose, "v", false, "enable verbose logging")
flag.Parse()
cache := NewCache()
connCfg := &rpcclient.ConnConfig{
Host: GetEnv("RPC_HOST", "localhost:8332"),
HTTPPostMode: true,
DisableTLS: true,
}
if GetEnv("RPC_USER", "") != "" {
connCfg.User = GetEnv("RPC_USER", "")
connCfg.Pass = GetEnv("RPC_PASS", "")
} else {
connCfg.CookiePath = GetEnv("RPC_COOKIE_PATH", "")
}
waitForTxIndex := false
if GetEnv("TXINDEX_ENABLED", "") == "true" {
waitForTxIndex = true
}
waitForFeeEstimation := false
if GetEnv("FEE_ESTIMATION_ENABLED", "") == "true" {
waitForFeeEstimation = true
}
client, err := rpcclient.New(connCfg, nil)
if err != nil {
log.Fatalf("Failed to create client: %s", err)
}
defer client.Shutdown()
cacheExpireSeconds, err := strconv.Atoi(GetEnv("CACHE_EXPIRE_SECONDS", "14"))
if err != nil {
log.Fatalf("Could not convert %s to integer: %s", GetEnv("CACHE_EXPIRE_SECONDS", "14"), err)
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
handleHealthcheck(w, r, client, time.Duration(time.Duration(cacheExpireSeconds)*time.Second), waitForTxIndex, waitForFeeEstimation, cache)
})
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", GetEnv("PORT", "8080")), nil))
}