mirror of
https://github.com/hanzoai/ingress-parser.git
synced 2026-10-30 18:33:22 +00:00
Rebrand module path, DefaultNamePrefix TRAEFIK_ -> INGRESS_, DefaultRootName traefik -> ingress, config paths /etc/traefik -> /etc/ingress. All 7 packages pass tests.
33 lines
765 B
Go
33 lines
765 B
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/hanzoai/ingress-parser/env"
|
|
)
|
|
|
|
// EnvLoader loads a configuration from all the environment variables prefixed with Prefix (default: "INGRESS_").
|
|
type EnvLoader struct {
|
|
Prefix string
|
|
}
|
|
|
|
// Load loads the command's configuration from the environment variables.
|
|
func (e *EnvLoader) Load(_ []string, cmd *Command) (bool, error) {
|
|
prefix := env.DefaultNamePrefix
|
|
if e.Prefix != "" {
|
|
prefix = e.Prefix
|
|
}
|
|
|
|
vars := env.FindPrefixedEnvVars(os.Environ(), prefix, cmd.Configuration)
|
|
if len(vars) == 0 {
|
|
return false, nil
|
|
}
|
|
|
|
if err := env.Decode(vars, prefix, cmd.Configuration); err != nil {
|
|
return false, fmt.Errorf("failed to decode configuration from environment variables: %w ", err)
|
|
}
|
|
|
|
return true, nil
|
|
}
|