🔒 Audit
Performs a security audit on the current project's dependencies and returns the output in Composer's standard text format. Equivalent to running composer audit.
When to use
Use when you only need to check whether the project has known security vulnerabilities and display the results as human-readable text. If you need to further process vulnerability data in code, use AuditWithJSON or GetAuditInfo instead.
Signature
go
func (c *Composer) Audit() (string, error)Parameters
This method takes no parameters.
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | Standard output text of composer audit |
| Second return value | error | Returned when an error occurs during execution; nil indicates success |
Note
When the audit finds vulnerabilities, Composer exits with a non-zero exit code, and this method may return an error. If you want to obtain results even when vulnerabilities are found, use HasVulnerabilities or GetAuditInfo.
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)
}
output, err := comp.Audit()
if err != nil {
log.Fatalf("failed to run security audit: %v", err)
}
fmt.Println("Security audit result:")
fmt.Println(output)
}Advanced
- For structured data: use AuditWithJSON to get an
*AuditResult. - To exclude development dependencies: use AuditWithoutDev.
- To customize the output format: use AuditWithFormat.
- For fully custom options: use
AuditWithOptions(options map[string]string), which can take multiple parameters such asno-dev,format, andlockedat once.