mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 14:32:24 -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
				
			
		|  | @ -32,29 +32,17 @@ func init() { | |||
| // package, and instead pass the ConfigState round in a global gts state. | ||||
| 
 | ||||
| // Config provides you safe access to the global configuration. | ||||
| func Config(fn func(cfg *Configuration)) { | ||||
| 	global.Config(fn) | ||||
| } | ||||
| func Config(fn func(cfg *Configuration)) { global.Config(fn) } | ||||
| 
 | ||||
| // Reload will reload the current configuration values from file. | ||||
| func Reload() error { | ||||
| 	return global.Reload() | ||||
| } | ||||
| 
 | ||||
| // LoadEarlyFlags will bind specific flags from given Cobra command to global viper | ||||
| // instance, and load the current configuration values. This is useful for flags like | ||||
| // .ConfigPath which have to parsed first in order to perform early configuration load. | ||||
| func LoadEarlyFlags(cmd *cobra.Command) error { | ||||
| 	return global.LoadEarlyFlags(cmd) | ||||
| } | ||||
| // RegisterGlobalFlags ... | ||||
| func RegisterGlobalFlags(root *cobra.Command) { global.RegisterGlobalFlags(root) } | ||||
| 
 | ||||
| // BindFlags binds given command's pflags to the global viper instance. | ||||
| func BindFlags(cmd *cobra.Command) error { | ||||
| 	return global.BindFlags(cmd) | ||||
| } | ||||
| func BindFlags(cmd *cobra.Command) error { return global.BindFlags(cmd) } | ||||
| 
 | ||||
| // LoadConfigFile loads the currently set configuration file into the global viper instance. | ||||
| func LoadConfigFile() error { return global.LoadConfigFile() } | ||||
| 
 | ||||
| // Reset will totally clear global | ||||
| // ConfigState{}, loading defaults. | ||||
| func Reset() { | ||||
| 	global.Reset() | ||||
| } | ||||
| func Reset() { global.Reset() } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue