📊 GetConfigStructured
Gets all Composer configuration items for the current project and parses the text output into the structured *ConfigResult. Equivalent to running composer config --list and automatically parsing it.
When to use
Use it when you need to iterate over configuration items programmatically, filter by key, or perform bulk comparisons. Compared to the raw string returned by ListConfig, the structured result is more suitable for machine processing.
Signature
go
func (c *Composer) GetConfigStructured() (*ConfigResult, error)Parameters
This method takes no parameters.
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | *ConfigResult | Parsed configuration result |
| Second return value | error | Returned when execution fails |
Fields of ConfigResult and ConfigItem:
| Field | Type | Description |
|---|---|---|
ConfigResult.Items | []ConfigItem | List of all configuration items |
ConfigItem.Key | string | Configuration item name |
ConfigItem.Value | string | Configuration item value |
ConfigItem.Source | string | Configuration source (usually empty during parsing) |
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.Fatalf("initialization failed: %v", err)
}
result, err := comp.GetConfigStructured()
if err != nil {
log.Fatalf("failed to get configuration: %v", err)
}
for _, item := range result.Items {
fmt.Printf("%s = %s\n", item.Key, item.Value)
}
}Advanced
- The underlying parser function
ParseConfigList(output string) *ConfigResultcan be used independently to parse anycomposer config --listtext. - For the raw text only, use ListConfig.
- For a single configuration item only, use GetConfigWithGlobal.