🌐 SetEnvVariable
Sets a Composer environment variable. Equivalent to calling os.Setenv from the Go standard library, with the key being an EnvironmentVariable constant (e.g. COMPOSER_HOME).
When to use
Use this when you need to adjust Composer behavior at the process level (custom home directory, cache directory, timeout, etc.). Environment variables take precedence over config files, making them suitable for CI/container scenarios.
Signature
go
func SetEnvVariable(name EnvironmentVariable, value string) errorParameters
| Parameter | Type | Description |
|---|---|---|
name | EnvironmentVariable | Environment variable name, using a predefined constant such as EnvComposerHome |
value | string | Value to set |
Common constants: EnvComposerHome, EnvComposerCacheDir, EnvComposerProcessTimeout, EnvComposerMemoryLimit, EnvComposerNoInteraction, EnvComposerVendorDir, etc.
Return value
| Return value | Type | Description |
|---|---|---|
| Sole return value | error | Returned when the setting fails (usually nil) |
Example
go
package main
import (
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
if err := composer.SetEnvVariable(composer.EnvComposerHome, "/opt/composer-home"); err != nil {
log.Fatalf("set env variable failed: %v", err)
}
}Advanced
- To read an environment variable, use GetEnvVariable.
- Dedicated shortcut functions exist for setting timeout, memory limit, and disabling interaction: SetProcessTimeout, SetMemoryLimit, DisableInteraction.
- This is a package-level function (not a
Composermethod) and affects the environment of the entire process.