📊 AuditWithFormat
Performs a security audit with the specified output format. Equivalent to running composer audit --format=FORMAT.
When to use
Use when you need to control how the audit output is presented. Common formats include json (structured), table (table, easy to read by eye), and plain (plain text). To get a parsed Go struct directly, use AuditWithJSON.
Signature
go
func (c *Composer) AuditWithFormat(format string) (string, error)Parameters
| Parameter | Type | Description |
|---|---|---|
format | string | Output format, e.g. "json", "table", "plain" |
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | Audit output text in the specified format |
| 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)
}
// Output as a table, easy to read by eye
output, err := comp.AuditWithFormat("table")
if err != nil {
log.Fatalf("failed to run security audit: %v", err)
}
fmt.Println(output)
// Output as plain text
plain, err := comp.AuditWithFormat("plain")
if err != nil {
log.Fatalf("failed to run security audit: %v", err)
}
fmt.Println(plain)
}Advanced
- To get JSON and a parsed struct directly: use AuditWithJSON.
- To specify multiple options at once (e.g.
no-dev+format): useAuditWithOptions(map[string]string). - Related methods: Audit, AuditWithoutDev.