From 6acf56cde9fde972cf7c78f15d00ade262752c19 Mon Sep 17 00:00:00 2001 From: kim Date: Tue, 6 May 2025 15:51:45 +0000 Subject: [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 Co-committed-by: kim --- internal/config/defaults.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'internal/config/defaults.go') diff --git a/internal/config/defaults.go b/internal/config/defaults.go index e3ea64592..6e4d7e09a 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -130,15 +130,23 @@ var Defaults = Configuration{ SyslogProtocol: "udp", SyslogAddress: "localhost:514", - AdvancedCookiesSamesite: "lax", - AdvancedRateLimitRequests: 300, // 1 per second per 5 minutes - AdvancedRateLimitExceptions: IPPrefixes{}, - AdvancedThrottlingMultiplier: 8, // 8 open requests per CPU - AdvancedThrottlingRetryAfter: time.Second * 30, - AdvancedSenderMultiplier: 2, // 2 senders per CPU - AdvancedCSPExtraURIs: []string{}, - AdvancedHeaderFilterMode: RequestHeaderFilterModeDisabled, - AdvancedScraperDeterrence: false, + Advanced: AdvancedConfig{ + SenderMultiplier: 2, // 2 senders per CPU + CSPExtraURIs: []string{}, + HeaderFilterMode: RequestHeaderFilterModeDisabled, + CookiesSamesite: "lax", + ScraperDeterrence: false, + + RateLimit: RateLimitConfig{ + Requests: 300, // 1 per second per 5 minutes + Exceptions: IPPrefixes{}, + }, + + Throttling: ThrottlingConfig{ + Multiplier: 8, // 8 open requests per CPU + RetryAfter: 30 * time.Second, + }, + }, Cache: CacheConfiguration{ // Rough memory target that the total -- cgit v1.2.3