trait

package
v0.0.40 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCatalogNotFound = errors.New("trait catalog not found")

ErrCatalogNotFound is returned when the catalog.yaml cannot be located.

Functions

func CatalogBaseDir

func CatalogBaseDir() string

CatalogBaseDir returns the directory from which traits are loaded. Traits live at <base>/traits/, ADRs at <base>/../adrs/, patterns at <base>/../patterns/.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns true if the error is a NotFoundError.

Types

type ADRRef

type ADRRef struct {
	ID       string `json:"id"       yaml:"id"`
	Title    string `json:"title"    yaml:"title"`
	Category string `json:"category" yaml:"category"`
	File     string `json:"file"     yaml:"file"`
}

ADRRef references a single ADR artifact within a trait.

type Catalog

type Catalog struct {
	Traits []TraitRef `json:"traits" yaml:"traits"`
}

Catalog holds all trait references.

func LoadCatalog

func LoadCatalog() (*Catalog, error)

LoadCatalog reads the trait catalog from the process repo or working directory.

type Conflict

type Conflict struct {
	Category string
	Owners   []string
}

Conflict describes a category owned by more than one trait.

type ConflictStrategy

type ConflictStrategy int

ConflictStrategy determines how to handle conflicts.

const (
	ConflictStrategyFirst ConflictStrategy = iota
	ConflictStrategyLast
	ConflictStrategyAll
)

type NotFoundError

type NotFoundError struct {
	Name string
}

NotFoundError wraps a trait-not-found error.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type PatternRef

type PatternRef struct {
	ID       string `json:"id"       yaml:"id"`
	Title    string `json:"title"    yaml:"title"`
	Category string `json:"category" yaml:"category"`
	File     string `json:"file"     yaml:"file"`
}

PatternRef references a single pattern artifact within a trait.

type ResolveResult

type ResolveResult struct {
	Traits    []string
	ADRs      []ADRRef
	Patterns  []PatternRef
	Conflicts []Conflict
}

ResolveResult is the output of the resolver.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver resolves a list of trait names into a merged set of ADRs and patterns, detecting and handling conflicts.

func NewResolver

func NewResolver(catalog *Catalog) *Resolver

NewResolver creates a new Resolver backed by the given catalog.

func (*Resolver) Resolve

func (r *Resolver) Resolve(names []string) (*ResolveResult, error)

Resolve expands all named traits (including sub-traits via Uses) and collects their ADRs, patterns, and any category ownership conflicts.

func (*Resolver) ResolveConflicts

func (r *Resolver) ResolveConflicts(result *ResolveResult, strategy ConflictStrategy) *ResolveResult

ResolveConflicts applies a conflict resolution strategy to a ResolveResult.

type Trait

type Trait struct {
	Name           string       `json:"name"            yaml:"name"`
	Version        string       `json:"version"         yaml:"version"`
	Description    string       `json:"description"     yaml:"description"`
	Uses           []string     `json:"uses"            yaml:"uses"`
	ADRs           []ADRRef     `json:"adrs"            yaml:"adrs"` //nolint:tagliatelle // "adrs" is the correct domain key; "adRs" would be confusing
	Patterns       []PatternRef `json:"patterns"        yaml:"patterns"`
	OwnsCategories []string     `json:"owns_categories" yaml:"owns_categories"` //nolint:tagliatelle // snake_case matches trait YAML file format
}

Trait is the full definition of a trait loaded from its YAML file.

func LoadTrait

func LoadTrait(name string) (*Trait, error)

LoadTrait loads a trait by name from the catalog.

func LoadTraitFromFile

func LoadTraitFromFile(file string) (*Trait, error)

LoadTraitFromFile loads a trait directly from a YAML file path.

type TraitRef

type TraitRef struct {
	Name        string   `json:"name"        yaml:"name"`
	Version     string   `json:"version"     yaml:"version"`
	Description string   `json:"description" yaml:"description"`
	File        string   `json:"file"        yaml:"file"`
	Tags        []string `json:"tags"        yaml:"tags"`
}

TraitRef is an entry in the trait catalog index.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL