This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
77 lines (65 loc) · 2.13 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
package main
import (
"io/ioutil"
"gopkg.in/yaml.v3"
)
// Config to receive settings from the configuration file
type Config struct {
DatabaseFile string `yaml:"database-file"`
MaxBlocks int `yaml:"max-blocks"`
MaxPayments int `yaml:"max-payments"`
Pools []PoolConfig `yaml:"pools"`
Miners []MinerConfig `yaml:"miners"`
TelegramConfig TelegramConfig `yaml:"telegram"`
Notifications NotificationsConfig `yaml:"notifications"`
}
// PoolConfig to store Pool configuration
type PoolConfig struct {
Coin string `yaml:"coin"`
EnableBlocks bool `yaml:"enable-blocks"`
MinBlockReward float64 `yaml:"min-block-reward"`
}
// MinerConfig to store Miner configuration
type MinerConfig struct {
Address string `yaml:"address"`
Coin string `yaml:"coin"`
EnableBalance bool `yaml:"enable-balance"`
EnablePayments bool `yaml:"enable-payments"`
EnableOfflineWorkers bool `yaml:"enable-offline-workers"`
}
// TelegramConfig to store Telegram configuration
type TelegramConfig struct {
Token string `yaml:"token"`
ChatID int64 `yaml:"chat-id"`
ChannelName string `yaml:"channel-name"`
}
// NotificationTemplatesConfig to store all notifications configurations
type NotificationsConfig struct {
Balance NotificationConfig `yaml:"balance"`
Payment NotificationConfig `yaml:"payment"`
Block NotificationConfig `yaml:"block"`
OfflineWorker NotificationConfig `yaml:"offline-worker"`
}
// NotificationConfig to store a single notification configuration
type NotificationConfig struct {
Template string `yaml:"template"`
Test bool `yaml:"test"`
}
// NewConfig creates a Config with default values
func NewConfig() *Config {
return &Config{
DatabaseFile: AppName + ".db",
}
}
// ReadFile reads and parses a YAML configuration file to override default values
func (c *Config) ReadFile(filename string) (err error) {
yamlFile, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
err = yaml.Unmarshal(yamlFile, &c)
if err != nil {
return err
}
return nil
}