Archived
1
0
Fork 0
This repository has been archived on 2024-12-18. You can view files and clone it, but cannot push or open issues or pull requests.
flexassistant/config.go
Julien Riou d2d1503779
feat: ETC support and notifications tests
- Add ETC to the list of supported coins. A new `coin` setting can be
  configured to avoid conflict with `eth`. Mind the lowercase. By default,
  flexassitant will try to deduce the coin from the miner's address (with eth by
  default, not etc). (#5)

- Add `test` (true/false) to `notifications` section to test notifications with
  random values fetched from the Flexpool API

- Fix typo in the configuration example (#6)

BREAKING CHANGE: `notification-templates` configuration settings have been
renamed to `notifications`, with sections to configure balance, payment, block
and offline workers notifications, with `template` and `test` settings.

Signed-off-by: Julien Riou <julien@riou.xyz>
2022-02-27 20:26:36 +01:00

77 lines
2.1 KiB
Go

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
}