📁 GetVendorDir
Gets the vendor directory path, equivalent to running composer config vendor-dir.
When to use
Use this when you need to locate the dependency installation directory, or read a package's source code or resources. If the project has not customized vendor-dir, the default <working-directory>/vendor is returned.
Signature
go
func (c *Composer) GetVendorDir() (string, error)Parameters
This method takes no parameters.
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | The vendor directory path (customized value or default <working-directory>/vendor) |
| Second return value | error | Always nil (falls back to the default value when the command 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)
}
vendorDir, err := comp.GetVendorDir()
if err != nil {
log.Fatalf("Failed to get vendor directory: %v", err)
}
fmt.Printf("Vendor directory: %s\n", vendorDir)
}Advanced
- To only check whether the vendor directory exists, use HasVendorDir.
- To get the bin directory path, use
GetBinDir. - To get the Composer cache directory, use GetCacheDir.