Documentation
¶
Overview ¶
Package env loads environment variable files:
http-client.env.json {"dev": {"baseUrl": "..."}, "$shared": {...}}
http-client.private.env.json same shape, for secrets, gitignored
.env KEY=value lines
These are the conventions used by JetBrains HTTP Client, kulala.nvim and httpyac, so one set of files serves every tool.
Index ¶
- Constants
- type AuthConfig
- type Environments
- func (e *Environments) AllAuth() map[string]map[string]map[string]map[string]any
- func (e *Environments) Auth(env string) map[string]*AuthConfig
- func (e *Environments) AuthNames() []string
- func (e *Environments) Has(name string) bool
- func (e *Environments) Names() []string
- func (e *Environments) PrivateVars(env string) map[string]string
- func (e *Environments) PublicVars(env string) map[string]string
- func (e *Environments) SSL(env string) *SSLConfig
- type SSLConfig
Constants ¶
const ( PublicFile = "http-client.env.json" PrivateFile = "http-client.private.env.json" DotEnvFile = ".env" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthConfig ¶
type AuthConfig struct {
Name string
Fields map[string]any
Files []string // the env files that declare it
}
AuthConfig is one entry of a JetBrains `Security.Auth` block:
"Security": {
"Auth": {
"my-api": {"Type": "OAuth2", "Grant Type": "Client Credentials",
"Token URL": "https://idp/token", "Client ID": "{{clientId}}"}
}
}
Requests use it as {{$auth.token("my-api")}}. Fields are as written, so strings may hold {{placeholders}}; the private file's fields win over the public file's, and an environment's over $shared's.
type Environments ¶
type Environments struct {
Public map[string]map[string]string // env name -> vars
Private map[string]map[string]string
DotEnv map[string]string
Found []string // files that were present
// contains filtered or unexported fields
}
Environments is everything loaded from the env files of a project.
func Load ¶
func Load(root string) (*Environments, error)
Load reads the env files in root. Missing files are fine.
func (*Environments) AllAuth ¶
AllAuth is every Security.Auth entry as each file and environment declares it, for validate: file -> env -> name -> fields.
func (*Environments) Auth ¶
func (e *Environments) Auth(env string) map[string]*AuthConfig
Auth returns the Security.Auth configurations in effect for env, by name: $shared's and env's from the public file, then the private file's over them field by field.
func (*Environments) AuthNames ¶
func (e *Environments) AuthNames() []string
AuthNames is every Security.Auth name any environment declares, sorted.
func (*Environments) Has ¶
func (e *Environments) Has(name string) bool
Has reports whether an environment is declared in either JSON file.
func (*Environments) Names ¶
func (e *Environments) Names() []string
Names returns the environment names found in the JSON files, sorted.
func (*Environments) PrivateVars ¶
func (e *Environments) PrivateVars(env string) map[string]string
PrivateVars returns the private vars for env merged over $shared.
func (*Environments) PublicVars ¶
func (e *Environments) PublicVars(env string) map[string]string
PublicVars returns the public vars for env merged over $shared.
func (*Environments) SSL ¶
func (e *Environments) SSL(env string) *SSLConfig
SSL returns the SSLConfiguration block for env, merged over $shared, or nil when neither file declares one.
type SSLConfig ¶
SSLConfig is the JetBrains `SSLConfiguration` block of an environment:
"SSLConfiguration": {
"clientCertificate": {"path": "certs/client.pem", "keyPath": "certs/client-key.pem"},
"hasCertificatePassphrase": false,
"verifyHostCertificate": true
}
It is read from either env file (the private one wins) and is not a variable. Paths are relative to the project root.