🎯 CheckStructured
Checks whether composer.json and composer.lock are in sync and returns a structured result (validity + categorized messages/warnings/errors).
When to use
Use in CI pipelines that need to decide whether to allow a build based on the Valid boolean and report error details separately.
Signature
go
func (c *Composer) CheckStructured() (*CheckResult, error)Parameters
| Parameter | Type | Description |
|---|---|---|
| None | — | This method takes no parameters |
Return value
*CheckResult: Check result, includingValidand categorized messageserror: Error from executing the command (note: when there is an error,Validis set tofalse, but the result is still returned)
go
type CheckResult struct {
Valid bool `json:"valid"`
Messages []string `json:"messages,omitempty"`
Warnings []string `json:"warnings,omitempty"`
Errors []string `json:"errors,omitempty"`
}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.Fatal(err)
}
result, err := comp.CheckStructured()
if err != nil {
log.Printf("check encountered an error: %v", err)
}
if !result.Valid {
fmt.Println("Check failed, errors:")
for _, e := range result.Errors {
fmt.Println("- " + e)
}
} else {
fmt.Println("Check passed")
}
}Advanced
- Parsing is done by
ParseCheckOutput: lines matchingerror/Error/FAILare categorized as errors,warning/Warning/WARNas warnings, and the rest as messages - For the raw text version, see Check
- To validate the
composer.jsonschema strictly, useValidateStructured(see result_types.go)