Skip to content

📊 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

ParameterTypeDescription
formatstringOutput format, e.g. "json", "table", "plain"

Return value

Return valueTypeDescription
First return valuestringAudit output text in the specified format
Second return valueerrorReturned 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): use AuditWithOptions(map[string]string).
  • Related methods: Audit, AuditWithoutDev.

Released under the MIT License