1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/finnhub/settings.go
2020-10-19 20:51:39 +01:00

37 lines
999 B
Go

package finnhub
import (
"os"
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/utils"
)
const (
defaultFocusable = true
defaultTitle = "📈 Stocks Price"
)
// Settings defines the configuration properties for this module
type Settings struct {
common *cfg.Common
apiKey string `help:"Your finnhub API token."`
symbols []string `help:"An array of stocks symbols (i.e. AAPL, MSFT)"`
}
// NewSettingsFromYAML creates a new settings instance from a YAML config block
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
settings := Settings{
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_FINNHUB_API_KEY"))),
symbols: utils.ToStrs(ymlConfig.UList("symbols")),
}
cfg.ModuleSecret(name, globalConfig, &settings.apiKey).Load()
return &settings
}