diff --git a/config/config.go b/config/config.go index d1d41ff..82cf076 100644 --- a/config/config.go +++ b/config/config.go @@ -144,3 +144,10 @@ func (c *Config) SetValue(fieldValue func(fieldName string) string) { setValue(c.Elements, c.Languages, fieldValue) } } + +func (c *Config) GetValue(fieldValue func(fieldName string, fieldValue string) error) error { + if fieldValue != nil { + return getValue(c.Elements, c.Languages, fieldValue) + } + return nil +} diff --git a/config/utils.go b/config/utils.go index d0ca573..8acfdc8 100644 --- a/config/utils.go +++ b/config/utils.go @@ -76,3 +76,30 @@ func setValue(elements []*Element, languages []*Language, fieldValue func(string } } } + +func getValue(elements []*Element, languages []*Language, fieldValue func(string, string) error) (err error) { + for _, elem := range elements { + if elem.Type == `langset` { + getValue(elem.Elements, elem.Languages, fieldValue) + continue + } + if elem.Type == `fieldset` { + getValue(elem.Elements, languages, fieldValue) + continue + } + if len(elem.Name) > 0 { + if len(languages) == 0 { + if err = fieldValue(elem.Name, elem.Value); err != nil { + return + } + continue + } + for _, lang := range languages { + if err = fieldValue(lang.Name(elem.Name), elem.Value); err != nil { + return + } + } + } + } + return +}