feat: support whole config as env (#6336)

* fix existing env vars

* feat: support all config by env

* cleanup

* remove system users hook

* decode system users in setup
This commit is contained in:
Elio Bischof
2024-02-16 17:04:42 +01:00
committed by GitHub
parent 32c7efea73
commit 19af2f7372
7 changed files with 278 additions and 85 deletions

35
cmd/hooks/complex.go Normal file
View File

@@ -0,0 +1,35 @@
package hooks
import (
"encoding/json"
"net/http"
"reflect"
)
func SliceTypeStringDecode[T any](from, to reflect.Value) (any, error) {
into := make([]T, 0)
return complexTypeStringDecodeHook(from, to, into)
}
func MapTypeStringDecode[K ~string | ~int, V any](from, to reflect.Value) (any, error) {
into := make(map[K]V, 0)
return complexTypeStringDecodeHook(from, to, into)
}
func MapHTTPHeaderStringDecode(from, to reflect.Value) (any, error) {
into := http.Header{}
return complexTypeStringDecodeHook(from, to, into)
}
func complexTypeStringDecodeHook(from, to reflect.Value, out any) (any, error) {
fromInterface := from.Interface()
if to.Type() != reflect.TypeOf(out) {
return fromInterface, nil
}
data, ok := fromInterface.(string)
if !ok {
return fromInterface, nil
}
err := json.Unmarshal([]byte(data), &out)
return out, err
}