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

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