github.com/wtfutil/wtf@v0.43.0/modules/weatherservices/weather/settings.go (about) 1 package weather 2 3 import ( 4 "os" 5 6 "github.com/olebedev/config" 7 "github.com/wtfutil/wtf/cfg" 8 ) 9 10 const ( 11 defaultFocusable = true 12 defaultTitle = "Weather" 13 ) 14 15 type colors struct { 16 current string 17 } 18 19 type Settings struct { 20 colors 21 *cfg.Common 22 23 apiKey string 24 cityIDs []interface{} 25 language string 26 tempUnit string 27 useEmoji bool 28 compact bool 29 } 30 31 func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { 32 settings := Settings{ 33 Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig), 34 35 apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_OWM_API_KEY"))), 36 cityIDs: ymlConfig.UList("cityids"), 37 language: ymlConfig.UString("language", "EN"), 38 tempUnit: ymlConfig.UString("tempUnit", "C"), 39 useEmoji: ymlConfig.UBool("useEmoji", true), 40 compact: ymlConfig.UBool("compact", false), 41 } 42 43 settings.SetDocumentationPath("weather_services/weather/") 44 45 settings.colors.current = ymlConfig.UString("colors.current", "green") 46 47 return &settings 48 }