You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-12-03 22:59:10 +02:00
Allow embedded structs in env_options
This commit is contained in:
@@ -15,14 +15,27 @@ type EnvOptions map[string]interface{}
|
||||
// Fields in the options struct must have an `env` and `cfg` tag to be read
|
||||
// from the environment
|
||||
func (cfg EnvOptions) LoadEnvForStruct(options interface{}) {
|
||||
val := reflect.ValueOf(options).Elem()
|
||||
typ := val.Type()
|
||||
val := reflect.ValueOf(options)
|
||||
var typ reflect.Type
|
||||
if val.Kind() == reflect.Ptr {
|
||||
typ = val.Elem().Type()
|
||||
} else {
|
||||
typ = val.Type()
|
||||
}
|
||||
|
||||
for i := 0; i < typ.NumField(); i++ {
|
||||
// pull out the struct tags:
|
||||
// flag - the name of the command line flag
|
||||
// deprecated - (optional) the name of the deprecated command line flag
|
||||
// cfg - (optional, defaults to underscored flag) the name of the config file option
|
||||
field := typ.Field(i)
|
||||
fieldV := reflect.Indirect(val).Field(i)
|
||||
|
||||
if field.Type.Kind() == reflect.Struct && field.Anonymous {
|
||||
cfg.LoadEnvForStruct(fieldV.Interface())
|
||||
continue
|
||||
}
|
||||
|
||||
flagName := field.Tag.Get("flag")
|
||||
envName := field.Tag.Get("env")
|
||||
cfgName := field.Tag.Get("cfg")
|
||||
|
||||
Reference in New Issue
Block a user