mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 02:12:25 -05:00
[feature] support nested configuration files, and setting ALL configuration variables by CLI and env (#4109)
This updates our configuration code generator to now also include map marshal and unmarshalers. So we now have much more control over how things get read from pflags, and stored / read from viper configuration. This allows us to set ALL configuration variables by CLI and environment now, AND support nested configuration files. e.g.
```yaml
advanced:
scraper-deterrence = true
http-client:
allow-ips = ["127.0.0.1"]
```
is the same as
```yaml
advanced-scraper-deterrence = true
http-client-allow-ips = ["127.0.0.1"]
```
This also starts cleaning up of our jumbled Configuration{} type by moving the advanced configuration options into their own nested structs, also as a way to show what it's capable of. It's worth noting however that nesting only works if the Go types are nested too (as this is how we hint to our code generator to generate the necessary flattening code :p).
closes #3195
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4109
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
7d74548a91
commit
6acf56cde9
30 changed files with 4764 additions and 1184 deletions
|
|
@ -18,6 +18,8 @@
|
|||
package language
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/language/display"
|
||||
|
|
@ -95,13 +97,35 @@ func (l *Language) UnmarshalText(text []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*l = *lang
|
||||
return nil
|
||||
}
|
||||
|
||||
type Languages []*Language
|
||||
|
||||
func (l *Languages) Set(in string) error {
|
||||
if l == nil {
|
||||
return errors.New("nil receiver")
|
||||
}
|
||||
prefix, err := Parse(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
(*l) = append((*l), prefix)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *Languages) Strings() []string {
|
||||
if l == nil || len(*l) == 0 {
|
||||
return nil
|
||||
}
|
||||
strs := make([]string, len(*l))
|
||||
for i, lang := range *l {
|
||||
strs[i] = lang.TagStr
|
||||
}
|
||||
return strs
|
||||
}
|
||||
|
||||
func (l Languages) Tags() []language.Tag {
|
||||
tags := make([]language.Tag, len(l))
|
||||
for i, lang := range l {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue