mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 20:55:42 +00:00
refactor: rework decoders logic for cleaner code (#431)
* refactor: rework decoders logic for cleaner code * refactor: use strcase lib to handle text case conversions
This commit is contained in:
@@ -1,20 +1,19 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"tinyauth/internal/config"
|
||||
|
||||
"github.com/traefik/paerser/parser"
|
||||
)
|
||||
|
||||
func DecodeEnv(env map[string]string) (config.Providers, error) {
|
||||
normalized := NormalizeKeys(env, "tinyauth", "_")
|
||||
var providers config.Providers
|
||||
func DecodeEnv[T any, C any](env map[string]string, subName string) (T, error) {
|
||||
var result T
|
||||
|
||||
err := parser.Decode(normalized, &providers, "tinyauth", "tinyauth.providers")
|
||||
normalized := normalizeKeys[C](env, subName, "_")
|
||||
|
||||
err := parser.Decode(normalized, &result, "tinyauth", "tinyauth."+subName)
|
||||
|
||||
if err != nil {
|
||||
return config.Providers{}, err
|
||||
return result, err
|
||||
}
|
||||
|
||||
return providers, nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user