env

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package env implements multi-environment management for nSelf projects. Each environment (dev, staging, prod) has its own .env file, Docker project name, network, and volume namespace to enable side-by-side operation.

Index

Constants

View Source
const DefaultEnv = "dev"

DefaultEnv is the environment used when none is explicitly set.

Variables

View Source
var PortShifts = map[string]int{
	"dev":     0,
	"staging": 100,
	"prod":    200,
}

PortShifts maps environment names to port offset values. dev=default, staging=+100, prod=+200.

Functions

func ActiveEnv

func ActiveEnv(projectDir string) string

ActiveEnv reads the currently active environment from .nself/active_env. Returns DefaultEnv if the file does not exist.

func Copy

func Copy(projectDir, fromEnv, toEnv string) error

Copy scaffolds a new environment by copying an existing one.

func DockerProjectName

func DockerProjectName(projectName, env string) string

DockerProjectName returns the Docker Compose project name for a given project and environment: nself-{project}-{env}.

func SetActiveEnv

func SetActiveEnv(projectDir, env string) error

SetActiveEnv writes the active environment to .nself/active_env.

func ShiftPort

func ShiftPort(basePort int, env string) int

ShiftPort applies the environment port offset to a base port.

Types

type DiffEntry

type DiffEntry struct {
	Key    string
	ValueA string // value in env A (empty = not present)
	ValueB string // value in env B (empty = not present)
}

DiffEntry describes a difference between two environments.

func Diff

func Diff(projectDir, envA, envB string) ([]DiffEntry, error)

Diff compares two environment configs and returns differences.

type EnvInfo

type EnvInfo struct {
	Name   string
	Active bool
	File   string
}

EnvInfo describes an available environment.

func List

func List(projectDir string) []EnvInfo

List returns all available environments for a project by scanning for .env.{name} files plus the active env.

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

KeyValue is a key-value pair from an env file.

func Show

func Show(projectDir, env string) ([]KeyValue, error)

Show returns key-value pairs for the given environment with secrets redacted.

Jump to

Keyboard shortcuts

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