env

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func (e *Environments) AllAuth() map[string]map[string]map[string]map[string]any

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

type SSLConfig struct {
	CertFile      string
	KeyFile       string
	HasPassphrase bool
	VerifyHost    *bool
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL