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

     1  package toplist
     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  	limit       int
    38  	to          []interface{}
    39  }
    40  
    41  type Settings struct {
    42  	*cfg.Common
    43  
    44  	colors
    45  	top map[string]*currency
    46  }
    47  
    48  func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
    49  
    50  	settings := Settings{
    51  		Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
    52  	}
    53  
    54  	settings.colors.from.name = ymlConfig.UString("colors.from.name")
    55  	settings.colors.from.displayName = ymlConfig.UString("colors.from.displayName")
    56  
    57  	settings.colors.to.name = ymlConfig.UString("colors.to.name")
    58  	settings.colors.to.price = ymlConfig.UString("colors.to.price")
    59  
    60  	settings.colors.top.from.name = ymlConfig.UString("colors.top.from.name")
    61  	settings.colors.top.from.displayName = ymlConfig.UString("colors.top.from.displayName")
    62  
    63  	settings.colors.top.to.name = ymlConfig.UString("colors.top.to.name")
    64  	settings.colors.top.to.field = ymlConfig.UString("colors.top.to.field")
    65  	settings.colors.top.to.value = ymlConfig.UString("colors.top.to.value")
    66  
    67  	settings.top = make(map[string]*currency)
    68  
    69  	for key, val := range ymlConfig.UMap("top") {
    70  		coercedVal := val.(map[string]interface{})
    71  
    72  		limit, _ := coercedVal["limit"].(int)
    73  
    74  		currency := &currency{
    75  			displayName: coercedVal["displayName"].(string),
    76  			limit:       limit,
    77  			to:          coercedVal["to"].([]interface{}),
    78  		}
    79  
    80  		settings.top[key] = currency
    81  	}
    82  
    83  	return &settings
    84  }