1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
Sean Smith 5abd701b40 Decouple modules from global config
Rather than referencing wtc.Config, instead pass the global config
Also, look up config for the module early and pass that in sooner, to deal with fewer long paths and get rid of the
ConfigKey variable
2019-04-27 22:26:23 -04:00

75 lines
1.9 KiB
Go

package cryptolive
import (
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/modules/cryptoexchanges/cryptolive/price"
"github.com/wtfutil/wtf/modules/cryptoexchanges/cryptolive/toplist"
)
const configKey = "cryptolive"
type colors struct {
from struct {
name string
displayName string
}
to struct {
name string
price string
}
top struct {
from struct {
name string
displayName string
}
to struct {
name string
field string
value string
}
}
}
type Settings struct {
colors
common *cfg.Common
currencies map[string]interface{}
top map[string]interface{}
priceSettings *price.Settings
toplistSettings *toplist.Settings
}
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
currencies, _ := ymlConfig.Map("currencies")
top, _ := ymlConfig.Map("top")
settings := Settings{
common: cfg.NewCommonSettingsFromModule(name, ymlConfig, globalConfig),
currencies: currencies,
top: top,
priceSettings: price.NewSettingsFromYAML(name, ymlConfig, globalConfig),
toplistSettings: toplist.NewSettingsFromYAML(name, ymlConfig, globalConfig),
}
settings.colors.from.name = ymlConfig.UString("colors.from.name")
settings.colors.from.displayName = ymlConfig.UString("colors.from.displayName")
settings.colors.to.name = ymlConfig.UString("colors.to.name")
settings.colors.to.price = ymlConfig.UString("colors.to.price")
settings.colors.top.from.name = ymlConfig.UString("colors.top.from.name")
settings.colors.top.from.displayName = ymlConfig.UString("colors.top.from.displayName")
settings.colors.top.to.name = ymlConfig.UString("colors.top.to.name")
settings.colors.top.to.field = ymlConfig.UString("colors.top.to.field")
settings.colors.top.to.value = ymlConfig.UString("colors.top.to.value")
return &settings
}