github.com/wtfutil/wtf@v0.43.0/modules/krisinformation/settings.go (about)

     1  package krisinformation
     2  
     3  import (
     4  	"github.com/olebedev/config"
     5  	"github.com/wtfutil/wtf/cfg"
     6  )
     7  
     8  const (
     9  	defaultFocusable = false
    10  	defaultTitle     = "Krisinformation"
    11  	defaultRadius    = -1
    12  	defaultCountry   = true
    13  	defaultCounty    = ""
    14  	defaultMaxItems  = -1
    15  	defaultMaxAge    = 720
    16  )
    17  
    18  // Settings defines the configuration properties for this module
    19  type Settings struct {
    20  	common    *cfg.Common
    21  	latitude  float64 `help:"The latitude of the position from which the widget should look for messages." optional:"true"`
    22  	longitude float64 `help:"The longitude of the position from which the widget should look for messages." optional:"true"`
    23  	radius    int     `help:"The radius in km from your position that the widget should look for messages. need latitude/longitude setting,Default 10" optional:"true"`
    24  	county    string  `help:"The county from where to display messages" optional:"true"`
    25  	country   bool    `help:"Only display country wide messages" optional:"true"`
    26  	maxitems  int     `help:"Only display X number of latest messages" optional:"true"`
    27  	maxage    int     `help:"Only show messages younger than maxage" optional:"true"`
    28  }
    29  
    30  // NewSettingsFromYAML creates a new settings instance from a YAML config block
    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  		latitude:  ymlConfig.UFloat64("latitude", -1),
    35  		longitude: ymlConfig.UFloat64("longitude", -1),
    36  		radius:    ymlConfig.UInt("radius", defaultRadius),
    37  		country:   ymlConfig.UBool("country", defaultCountry),
    38  		county:    ymlConfig.UString("county", defaultCounty),
    39  		maxitems:  ymlConfig.UInt("maxitems", defaultMaxItems),
    40  		maxage:    ymlConfig.UInt("maxages", defaultMaxAge),
    41  	}
    42  
    43  	return &settings
    44  }