📦 AuditLock
Performs a security audit on the specified composer.lock file. Equivalent to running composer audit [lockFilePath].
When to use
Use when you need to audit a lock file for a project that has not yet run composer install, or a lock file in another project's directory. Pass an empty string to audit the lock file in the current directory.
Signature
go
func (c *Composer) AuditLock(lockFilePath string) (string, error)Parameters
| Parameter | Type | Description |
|---|---|---|
lockFilePath | string | Path to the composer.lock file; when empty, the lock file in the current directory is used |
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | Standard output text of the audit command |
| Second return value | error | Returned when an error occurs during execution |
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.NewComposer("")
if err != nil {
log.Fatalf("init failed: %v", err)
}
// Audit the current project's lock file
output, err := comp.AuditLock("")
if err != nil {
log.Fatalf("failed to audit lock file: %v", err)
}
fmt.Println(output)
// Audit another project's lock file
other, err := comp.AuditLock("/path/to/other/project/composer.lock")
if err != nil {
log.Fatalf("failed to audit lock file: %v", err)
}
fmt.Println(other)
}Advanced
- This method returns text output; to process lock file audit results in a structured way, use
AuditWithOptionswithformat=json, then apply the parsing logic of GetAuditInfo. - Related methods: Audit, AuditWithJSON, AuditWithFormat.