profile

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package profile provides profile and store management for environment variable sets.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedFileType is returned when the file type is not supported.
	ErrUnsupportedFileType = errors.New("unsupported file type")
	// ErrProfileNotFound is returned when a profile is not found in the store.
	ErrProfileNotFound = errors.New("profile not found")
)

Functions

func Stringify

func Stringify(v any) (string, error)

Stringify turns any Go value into the dotenv-ready string described earlier.

  • Scalars → plain strings (`true`, `5432`, `foo`…).
  • Slices / maps / structs → compact JSON wrapped in single quotes (`'["a","b"]'`, `'{"k":"v"}'`).

Types

type Env

type Env map[string]any

Env is a map of environment variable names to their non-stringified values.

func (*Env) FromEnv added in v0.0.2

func (e *Env) FromEnv(env env.Env)

FromEnv initializes Env from an env.Env.

func (*Env) Stringified added in v0.0.1

func (e *Env) Stringified() (env.Env, error)

Stringified serializes Env into env.Env using Stringify. – Scalars pass through unchanged. – Non-scalars are JSON-minified and single-quoted (see Stringify).

func (*Env) UnmarshalYAML added in v0.0.2

func (e *Env) UnmarshalYAML(node ast.Node) error

UnmarshalYAML allows Env to be unmarshaled as its regular type or a sequence of strings.

type Inheritance

type Inheritance map[string]string

Inheritance carries a mapping from environment variable names to where they are inherited from.

type InheritanceTracker added in v0.0.1

type InheritanceTracker struct {
	// Inheritance is a mapping from environment variable names to where they are inherited from.
	Inheritance Inheritance
	// Env is the environment variables.
	Env env.Env
	// Name is the name of the profile.
	Name string
}

InheritanceTracker holds the environment variables and their inheritance sources.

func (InheritanceTracker) Format added in v0.0.1

func (i InheritanceTracker) Format(key string, verbose, withKey bool) string

Format returns the formatted value of a single variable.

func (InheritanceTracker) FormatAll added in v0.0.1

func (i InheritanceTracker) FormatAll(prefix string, verbose bool) string

FormatAll returns all variables, one per line.

type Profile

type Profile struct {
	Env     Env      `toml:"env,omitempty"     yaml:"env,omitempty"`
	DotEnv  []string `toml:"dotenv,omitempty"  yaml:"dotenv,omitempty"`
	Extends []string `toml:"extends,omitempty" yaml:"extends,omitempty"`
}

Profile holds metadata plus an env-var map.

type Profiles

type Profiles map[string]*Profile

Profiles is a map of profile names to their metadata.

func (Profiles) Create added in v0.0.1

func (p Profiles) Create(name string)

Create creates a new profile in the store.

func (Profiles) Environment added in v0.0.1

func (p Profiles) Environment(name string) (*InheritanceTracker, error)

Environment returns the merged environment variables for a profile, resolving dependencies.

func (Profiles) Exists added in v0.0.1

func (p Profiles) Exists(name string) bool

Exists checks if a profile exists in the store.

func (Profiles) Names added in v0.0.1

func (p Profiles) Names() []string

Names returns the names of the profiles in sorted order.

type Store

type Store struct {
	// File is the file containing the profiles.
	File file.File
	// Profiles is a map of profile names to their metadata.
	Profiles Profiles
	// Type is the type of the file.
	Type Type
}

Store represents the entire file and codec information.

func New

func New(file file.File) (*Store, error)

New creates a new store from the given path.

func (*Store) Load

func (s *Store) Load() (*Store, error)

Load reads the file and unmarshals it into the store.

type Type

type Type string

Type represents the type of the profile file.

const (
	// YAML is the YAML file type.
	YAML Type = "yaml"
	// TOML is the TOML file type.
	TOML Type = "toml"
)

Jump to

Keyboard shortcuts

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