github.com/wtfutil/wtf@v0.43.0/modules/cryptocurrency/cryptolive/price/settings.go (about) 1 package price 2 3 import ( 4 "github.com/olebedev/config" 5 "github.com/wtfutil/wtf/cfg" 6 ) 7 8 const ( 9 defaultFocusable = false 10 defaultTitle = "CryptoLive" 11 ) 12 13 type colors struct { 14 from struct { 15 name string 16 displayName string 17 } 18 to struct { 19 name string 20 price string 21 } 22 top struct { 23 from struct { 24 name string 25 displayName string 26 } 27 to struct { 28 name string 29 field string 30 value string 31 } 32 } 33 } 34 35 type currency struct { 36 displayName string 37 to []interface{} 38 } 39 40 type Settings struct { 41 *cfg.Common 42 43 colors 44 currencies map[string]*currency 45 } 46 47 func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { 48 49 settings := Settings{ 50 Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig), 51 } 52 53 settings.colors.from.name = ymlConfig.UString("colors.from.name") 54 settings.colors.from.displayName = ymlConfig.UString("colors.from.displayName") 55 56 settings.colors.to.name = ymlConfig.UString("colors.to.name") 57 settings.colors.to.price = ymlConfig.UString("colors.to.price") 58 59 settings.colors.top.from.name = ymlConfig.UString("colors.top.from.name") 60 settings.colors.top.from.displayName = ymlConfig.UString("colors.top.from.displayName") 61 62 settings.colors.top.to.name = ymlConfig.UString("colors.top.to.name") 63 settings.colors.top.to.field = ymlConfig.UString("colors.top.to.field") 64 settings.colors.top.to.value = ymlConfig.UString("colors.top.to.value") 65 66 settings.currencies = make(map[string]*currency) 67 68 for key, val := range ymlConfig.UMap("currencies") { 69 coercedVal := val.(map[string]interface{}) 70 71 currency := ¤cy{ 72 displayName: coercedVal["displayName"].(string), 73 to: coercedVal["to"].([]interface{}), 74 } 75 76 settings.currencies[key] = currency 77 } 78 79 return &settings 80 }