Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
admpub committed Oct 2, 2022
1 parent 0d4b640 commit 10ece58
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
27 changes: 27 additions & 0 deletions config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 10ece58

Please sign in to comment.