github.com/wtfutil/wtf@v0.43.0/modules/stocks/finnhub/settings.go (about) 1 package finnhub 2 3 import ( 4 "os" 5 6 "github.com/olebedev/config" 7 "github.com/wtfutil/wtf/cfg" 8 "github.com/wtfutil/wtf/utils" 9 ) 10 11 const ( 12 defaultFocusable = true 13 defaultTitle = "📈 Stocks Price" 14 ) 15 16 // Settings defines the configuration properties for this module 17 type Settings struct { 18 *cfg.Common 19 20 apiKey string `help:"Your finnhub API token."` 21 symbols []string `help:"An array of stocks symbols (i.e. AAPL, MSFT)"` 22 } 23 24 // NewSettingsFromYAML creates a new settings instance from a YAML config block 25 func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { 26 27 settings := Settings{ 28 Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig), 29 30 apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_FINNHUB_API_KEY"))), 31 symbols: utils.ToStrs(ymlConfig.UList("symbols")), 32 } 33 34 cfg.ModuleSecret(name, globalConfig, &settings.apiKey).Load() 35 36 return &settings 37 }