Documentation
¶
Overview ¶
Package env provides functions for manipulating .env files.
Index ¶
- func ApplyDatabaseConfig(envPath string, db DatabaseConfig) error
- func CopyTemplate(src, dst string) error
- func CopyTemplateIfExists(src, dst string) (bool, error)
- func Exists(path string) bool
- func FilterOutDatabaseKeys(values map[string]string) map[string]string
- func FindTemplate(envTemplatePath, projectPath string) string
- func GetValue(path, key string) (string, error)
- func IsDatabaseKey(key string) bool
- func Parse(path string) (map[string]string, error)
- func SetupEnvFile(templatePath, envPath string, values map[string]string) error
- func UpdateValue(path, key, value string) error
- func UpdateValues(path string, values map[string]string) error
- type DatabaseConfig
- type TemplateStatus
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 ¶
CopyTemplate copies an env template file to a destination. If the source doesn't exist, it returns an error.
func CopyTemplateIfExists ¶
CopyTemplateIfExists copies an env template if it exists. Returns true if copied, false if source didn't exist.
func FilterOutDatabaseKeys ¶
FilterOutDatabaseKeys removes database keys from a map.
func FindTemplate ¶
FindTemplate looks for an env template. Returns the path to the template found, or empty string if none. Search order:
- Explicit template path from config (envTemplatePath)
- .env.example in the project directory
func GetValue ¶
GetValue reads a single value from an env file. Returns empty string if key not found.
func IsDatabaseKey ¶
IsDatabaseKey returns true if the key is a database configuration key.
func SetupEnvFile ¶
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 ¶
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.
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.