-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
103 lines (89 loc) · 2.51 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"encoding/hex"
"fmt"
"log"
"net/http"
"git.ekzyis.com/ekzyis/delphi.market/db"
"git.ekzyis.com/ekzyis/delphi.market/env"
"git.ekzyis.com/ekzyis/delphi.market/lnd"
"git.ekzyis.com/ekzyis/delphi.market/server"
"git.ekzyis.com/ekzyis/delphi.market/server/router"
"github.com/lightninglabs/lndclient"
"github.com/namsral/flag"
)
var (
s *server.Server
)
func init() {
var (
dbUrl string
lndAddress string
lndCert string
tlsData []byte
lndMacaroon string
lndNetwork string
db_ *db.DB
lnd_ *lnd.LNDClient
ctx router.Context
err error
)
if err = env.Load(); err != nil {
log.Fatalf("error loading env vars: %v", err)
}
flag.StringVar(&dbUrl, "DATABASE_URL", "delphi.market", "Public URL of website")
flag.StringVar(&lndAddress, "LND_ADDRESS", "localhost:10001", "LND gRPC server address")
flag.StringVar(&lndCert, "LND_CERT", "", "LND TLS certificate in hex")
flag.StringVar(&lndMacaroon, "LND_MACAROON", "", "LND macaroon in hex")
flag.StringVar(&lndNetwork, "LND_NETWORK", "regtest", "LND network")
env.Parse()
figlet()
log.Printf("Commit: %s", env.CommitShortSha)
log.Printf("Public URL: %s", env.PublicURL)
log.Printf("Environment: %s", env.Env)
if db_, err = db.New(dbUrl); err != nil {
log.Fatalf("error connecting to database: %v", err)
}
if tlsData, err = hex.DecodeString(lndCert); err != nil {
log.Printf("[warn] error decoding LND TLS certificate: %v\n", err)
}
if lnd_, err = lnd.New(&lnd.LNDConfig{
LndAddress: lndAddress,
CustomMacaroonHex: lndMacaroon,
TLSData: string(tlsData),
Network: lndclient.Network(lndNetwork),
Insecure: false,
}); err != nil {
log.Printf("[warn] error connecting to LND: %v\n", err)
lnd_ = nil
} else {
go lnd_.CheckInvoices(db_)
}
ctx = server.Context{
Environment: env.Env,
PublicURL: env.PublicURL,
CommitShortSha: env.CommitShortSha,
CommitLongSha: env.CommitLongSha,
Version: env.Version,
Db: db_,
Lnd: lnd_,
}
s = server.New(ctx)
}
func figlet() {
log.Println(
"\n" +
" _ _ _ _ \n" +
" __| | ___| |_ __ | |__ (_)\n" +
" / _` |/ _ \\ | '_ \\| '_ \\| |\n" +
"| (_| | __/ | |_) | | | | |\n" +
" \\__,_|\\___|_| .__/|_| |_|_|\n" +
" |_| .market \n" +
"----------------------------",
)
}
func main() {
if err := s.Start(fmt.Sprintf("%s:%d", "127.0.0.1", env.Port)); err != http.ErrServerClosed {
log.Fatal(err)
}
}