[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:
kim
2025-05-06 15:51:45 +00:00
committed by kim
parent 7d74548a91
commit 6acf56cde9
30 changed files with 4764 additions and 1184 deletions

71
vendor/codeberg.org/gruf/go-split/join_util.go generated vendored Normal file
View File

@ -0,0 +1,71 @@
package split
import (
"strconv"
"strings"
)
// singleTermLine: beyond a certain length of string, all of the
// extra checks to handle quoting/not-quoting add a significant
// amount of extra processing time. Quoting in this manner only really
// effects readability on a single line, so a max string length that
// encompasses the maximum number of columns on *most* terminals was
// selected. This was chosen using the metric that 1080p is one of the
// most common display resolutions, and that a relatively small font size
// of 7 requires ~ 223 columns. So 256 should be >= $COLUMNS (fullscreen)
// in 99% of usecases (these figures all pulled out of my ass).
const singleTermLine = 256
// appendQuote will append 'str' to 'buf', double quoting and escaping if needed.
func appendQuote(buf []byte, str string) []byte {
switch {
case len(str) > singleTermLine || !strconv.CanBackquote(str):
// Append quoted and escaped string
return strconv.AppendQuote(buf, str)
case (strings.IndexByte(str, '"') != -1):
// Double quote and escape string
buf = append(buf, '"')
buf = appendEscape(buf, str)
buf = append(buf, '"')
return buf
case (strings.IndexByte(str, ',') != -1):
// Double quote this string as-is
buf = append(buf, '"')
buf = append(buf, str...)
buf = append(buf, '"')
return buf
default:
// Append string as-is
return append(buf, str...)
}
}
// appendEscape will append 'str' to 'buf' and escape any double quotes.
func appendEscape(buf []byte, str string) []byte {
var delim bool
for i := range str {
switch {
case str[i] == '\\' && !delim:
// Set delim flag
delim = true
case str[i] == '"' && !delim:
// Append escaped double quote
buf = append(buf, `\"`...)
case delim:
// Append skipped slash
buf = append(buf, `\`...)
delim = false
fallthrough
default:
// Append char as-is
buf = append(buf, str[i])
}
}
return buf
}