ResolveAPIKey resolves the endpoint's API key. A literal key stored on the endpoint (APIKey) wins; otherwise the value is read from the environment variable named by APIKeyEnv via the supplied env lookup function. Returns an empty string when neither is set. Callers should inject os.Getenv (or a tes
(e Endpoint, env func(string) string)
| 91 | // empty string when neither is set. Callers should inject os.Getenv (or a test |
| 92 | // stub) so this stays pure and easy to fake. |
| 93 | func ResolveAPIKey(e Endpoint, env func(string) string) string { |
| 94 | if strings.TrimSpace(e.APIKey) != "" { |
| 95 | return e.APIKey |
| 96 | } |
| 97 | if e.APIKeyEnv == "" || env == nil { |
| 98 | return "" |
| 99 | } |
| 100 | return env(e.APIKeyEnv) |
| 101 | } |
| 102 | |
| 103 | // ResolveAPIKeyEnv returns the environment-variable name that holds this |
| 104 | // endpoint's API key. When the endpoint sets APIKeyEnv explicitly that name is |
no outgoing calls