env

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package env provides functions for manipulating .env files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyDatabaseConfig

func ApplyDatabaseConfig(envPath string, db DatabaseConfig) error

ApplyDatabaseConfig applies database configuration to an env file.

func CopyTemplate

func CopyTemplate(src, dst string) error

CopyTemplate copies an env template file to a destination. If the source doesn't exist, it returns an error.

func CopyTemplateIfExists

func CopyTemplateIfExists(src, dst string) (bool, error)

CopyTemplateIfExists copies an env template if it exists. Returns true if copied, false if source didn't exist.

func Exists

func Exists(path string) bool

Exists checks if a .env file exists at the given path.

func FilterOutDatabaseKeys

func FilterOutDatabaseKeys(values map[string]string) map[string]string

FilterOutDatabaseKeys removes database keys from a map.

func FindTemplate

func FindTemplate(envTemplatePath, projectPath string) string

FindTemplate looks for an env template. Returns the path to the template found, or empty string if none. Search order:

  1. Explicit template path from config (envTemplatePath)
  2. .env.example in the project directory

func GetValue

func GetValue(path, key string) (string, error)

GetValue reads a single value from an env file. Returns empty string if key not found.

func IsDatabaseKey

func IsDatabaseKey(key string) bool

IsDatabaseKey returns true if the key is a database configuration key.

func Parse

func Parse(path string) (map[string]string, error)

Parse reads all key-value pairs from an env file.

func SetupEnvFile

func SetupEnvFile(templatePath, envPath string, values map[string]string) error

SetupEnvFile sets up a project's .env file from a template and applies values. templatePath: path to .env.example or custom template envPath: destination .env path values: key-value pairs to set

func UpdateValue

func UpdateValue(path, key, value string) error

UpdateValue updates or adds a single key-value pair in an env file. If the key exists, it replaces the value. If not, it appends the key.

func UpdateValues

func UpdateValues(path string, values map[string]string) error

UpdateValues updates or adds multiple key-value pairs in an env file. Existing keys are updated in place, new keys are appended.

Types

type DatabaseConfig

type DatabaseConfig struct {
	Connection string
	Host       string
	Port       int
	Database   string
	Username   string
	Password   string
}

DatabaseConfig holds database connection settings.

type TemplateStatus

type TemplateStatus struct {
	ProjectKey     string
	ConfiguredPath string // path from config (may not exist)
	Found          bool   // true if template file exists
	UsingFallback  bool   // true if will use .env.example
}

TemplateStatus holds information about a project's env template.

func CheckTemplate

func CheckTemplate(projectKey, envTemplatePath string) TemplateStatus

CheckTemplate checks the template status for a single project.

Jump to

Keyboard shortcuts

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