Skip to content

🔬 DiagnoseStructured ​

Runs composer diagnose and parses the output into a structured checklist, where each item carries an ok/warning/error status.

When to use ​

Use it when you need to branch programmatically on individual diagnostic results (for example, whether certificates are healthy or the Composer version is outdated).

Signature ​

go
func (c *Composer) DiagnoseStructured() (*DiagnoseResult, error)

Parameters ​

ParameterTypeDescription
None—This method takes no parameters

Return value ​

  • *DiagnoseResult: diagnostic result containing each check item
  • error: error encountered while running the command (note: even when an error is returned, the parsed result is still returned)
go
type DiagnoseResult struct {
    Checks []DiagnoseCheck `json:"checks,omitempty"`
}

type DiagnoseCheck struct {
    Name   string `json:"name"`
    Status string `json:"status"` // "ok", "warning", "error", "info"
    Detail string `json:"detail,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.DiagnoseStructured()
    if err != nil {
        log.Printf("diagnosis encountered an error: %v", err)
    }

    for _, check := range result.Checks {
        fmt.Printf("[%s] %s\n", check.Status, check.Detail)
    }
}

Advanced ​

  • Parsing is performed by ParseDiagnoseOutput: it detects [OK]/✓, [WARNING]/⚠, [ERROR]/✗ prefixes to determine the status
  • For the raw text version, see Diagnose
  • For a more comprehensive environment health summary, use HealthCheck

Released under the MIT License