-
Notifications
You must be signed in to change notification settings - Fork 41
/
config.go
81 lines (72 loc) · 2.17 KB
/
config.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
package main
import (
"fmt"
"net/url"
"strings"
"github.com/jinzhu/configor"
log "github.com/sirupsen/logrus"
)
var Configuration = struct {
Bot BotConfiguration `yaml:"bot"`
Telegram TelegramConfiguration `yaml:"telegram"`
Database DatabaseConfiguration `yaml:"database"`
Lnbits LnbitsConfiguration `yaml:"lnbits"`
}{}
type BotConfiguration struct {
HttpProxy string `yaml:"http_proxy"`
LNURLServer string `yaml:"lnurl_server"`
LNURLServerUrl *url.URL `yaml:"-"`
LNURLHostName string `yaml:"lnurl_public_host_name"`
LNURLHostUrl *url.URL `yaml:"-"`
}
type TelegramConfiguration struct {
MessageDisposeDuration int64 `yaml:"message_dispose_duration"`
ApiKey string `yaml:"api_key"`
}
type DatabaseConfiguration struct {
DbPath string `yaml:"db_path"`
BuntDbPath string `yaml:"buntdb_path"`
TransactionsPath string `yaml:"transactions_path"`
}
type LnbitsConfiguration struct {
AdminId string `yaml:"admin_id"`
AdminKey string `yaml:"admin_key"`
Url string `yaml:"url"`
LnbitsPublicUrl string `yaml:"lnbits_public_url"`
WebhookServer string `yaml:"webhook_server"`
WebhookServerUrl *url.URL `yaml:"-"`
}
func init() {
err := configor.Load(&Configuration, "config.yaml")
if err != nil {
panic(err)
}
webhookUrl, err := url.Parse(Configuration.Lnbits.WebhookServer)
if err != nil {
panic(err)
}
Configuration.Lnbits.WebhookServerUrl = webhookUrl
lnUrl, err := url.Parse(Configuration.Bot.LNURLServer)
if err != nil {
panic(err)
}
Configuration.Bot.LNURLServerUrl = lnUrl
hostname, err := url.Parse(Configuration.Bot.LNURLHostName)
if err != nil {
panic(err)
}
Configuration.Bot.LNURLHostUrl = hostname
checkLnbitsConfiguration()
}
func checkLnbitsConfiguration() {
if Configuration.Lnbits.Url == "" {
panic(fmt.Errorf("please configure a lnbits url"))
}
if Configuration.Lnbits.LnbitsPublicUrl == "" {
log.Warnf("Please specify a lnbits public url otherwise users won't be able to")
} else {
if !strings.HasSuffix(Configuration.Lnbits.LnbitsPublicUrl, "/") {
Configuration.Lnbits.LnbitsPublicUrl = Configuration.Lnbits.LnbitsPublicUrl + "/"
}
}
}