🏠 GetComposerHome
Gets the Composer home directory (COMPOSER_HOME) path. Equivalent to running composer config --global home.
When to use
Use it when you need to locate the directory where Composer stores global configuration, cache, and authentication information. Commonly used in custom tools that need to read auth.json, clear the cache, or back up global configuration.
Signature
go
func (c *Composer) GetComposerHome() (string, error)Parameters
This method takes no parameters.
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | Absolute path of the Composer home directory (leading and trailing whitespace removed) |
| Second return value | error | Returned when execution fails |
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatalf("initialization failed: %v", err)
}
home, err := comp.GetComposerHome()
if err != nil {
log.Fatalf("failed to get Composer home directory: %v", err)
}
fmt.Println("Composer home directory:", home)
}Advanced
- Similar convenience methods include
GetCacheDir(),GetVendorDir(), andGetBinDir(), which return the cache, vendor, and bin directories respectively. - This method is essentially a global read shortcut for the
homeitem via GetConfigWithGlobal. - To clear the cache directory, use ClearCache.