config

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config provides configuration loading for ctxweaver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CarrierDef

type CarrierDef struct {
	Package  string `yaml:"package" json:"package"`
	Type     string `yaml:"type" json:"type"`
	Accessor string `yaml:"accessor" json:"accessor,omitempty"`
}

CarrierDef defines a context carrier type.

func (CarrierDef) BuildContextExpr

func (c CarrierDef) BuildContextExpr(varName string) string

BuildContextExpr builds the expression to access context.Context from a variable.

type CarrierRegistry

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

CarrierRegistry holds all registered carriers for quick lookup.

func NewCarrierRegistry

func NewCarrierRegistry(includeDefaults bool) *CarrierRegistry

NewCarrierRegistry creates a registry, optionally loading default carriers.

func (*CarrierRegistry) All

func (r *CarrierRegistry) All() []CarrierDef

All returns all registered carriers.

func (*CarrierRegistry) Lookup

func (r *CarrierRegistry) Lookup(packagePath, typeName string) (CarrierDef, bool)

Lookup finds a carrier by package path and type name.

func (*CarrierRegistry) Register

func (r *CarrierRegistry) Register(c CarrierDef)

Register adds a carrier to the registry.

type Carriers added in v0.6.0

type Carriers struct {
	// Custom are user-defined carrier definitions
	Custom []CarrierDef
	// Default indicates whether to include default carriers (default: true)
	Default *bool
}

Carriers can be a simple array of CarrierDef or an object with custom/default fields. Simple form: carriers: [] Extended form: carriers: { custom: [], default: true }

func (Carriers) MarshalYAML added in v0.6.0

func (c Carriers) MarshalYAML() (any, error)

MarshalYAML implements custom marshaling for Carriers.

func (*Carriers) UnmarshalYAML added in v0.6.0

func (c *Carriers) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements custom unmarshaling for Carriers. Accepts either an array (simple form) or an object with "custom" and "default" fields.

func (*Carriers) UseDefault added in v0.6.0

func (c *Carriers) UseDefault() bool

UseDefault returns whether default carriers should be used.

type CarriersFile

type CarriersFile struct {
	Carriers []CarrierDef `yaml:"carriers"`
}

CarriersFile represents the structure of carriers.yaml.

type Config

type Config struct {
	// Template is the Go template for the statement to insert
	Template Template `yaml:"template" json:"template"`
	// Imports are the imports to add when the template is inserted
	Imports []string `yaml:"imports" json:"imports,omitempty"`
	// Carriers defines context carrier configuration (custom carriers and default toggle)
	Carriers Carriers `yaml:"carriers" json:"carriers,omitempty"`
	// Packages defines package filtering options
	Packages Packages `yaml:"packages" json:"packages"`
	// Functions defines function filtering options
	Functions Functions `yaml:"functions" json:"functions,omitempty"`
	// Test indicates whether to process test files
	Test bool `yaml:"test" json:"test,omitempty"`
	// Hooks are shell commands to run before and after processing
	Hooks Hooks `yaml:"hooks" json:"hooks,omitempty"`
}

Config represents the user configuration file.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads a configuration file.

func (*Config) SetDefaults added in v0.6.0

func (c *Config) SetDefaults()

SetDefaults sets default values for optional fields.

type FuncScope added in v0.6.0

type FuncScope string

FuncScope represents function scope for filtering.

const (
	FuncScopeExported   FuncScope = "exported"
	FuncScopeUnexported FuncScope = "unexported"
)

type FuncType added in v0.6.0

type FuncType string

FuncType represents function type for filtering.

const (
	FuncTypeFunction FuncType = "function"
	FuncTypeMethod   FuncType = "method"
)

type Functions added in v0.6.0

type Functions struct {
	// Types filters by function type (function, method). Default: both.
	Types []FuncType `yaml:"types" json:"types,omitempty"`
	// Scopes filters by visibility (exported, unexported). Default: both.
	Scopes []FuncScope `yaml:"scopes" json:"scopes,omitempty"`
	// Regexps for filtering functions by name
	Regexps Regexps `yaml:"regexps" json:"regexps,omitempty"`
}

Functions defines function filtering options.

type Hooks

type Hooks struct {
	// Pre are shell commands to run before processing
	Pre []string `yaml:"pre" json:"pre,omitempty"`
	// Post are shell commands to run after processing
	Post []string `yaml:"post" json:"post,omitempty"`
}

Hooks defines shell commands to run before and after processing.

type Packages added in v0.6.0

type Packages struct {
	// Patterns are the package patterns to process (e.g., "./...")
	Patterns []string `yaml:"patterns" json:"patterns"`
	// Regexps for filtering packages by import path
	Regexps Regexps `yaml:"regexps" json:"regexps,omitempty"`
}

Packages defines package filtering options.

type Regexps added in v0.6.0

type Regexps struct {
	// Only includes items matching these patterns (if specified)
	Only []string `yaml:"only" json:"only,omitempty"`
	// Omit excludes items matching these patterns
	Omit []string `yaml:"omit" json:"omit,omitempty"`
}

Regexps defines regex patterns for filtering.

type Template added in v0.6.0

type Template struct {
	Inline string
	File   string
}

Template can be an inline string or a reference to a file.

func (*Template) Content added in v0.6.0

func (t *Template) Content() (string, error)

Content returns the template content, loading from file if necessary.

func (Template) MarshalYAML added in v0.6.0

func (t Template) MarshalYAML() (any, error)

MarshalYAML implements custom marshaling for Template.

func (*Template) UnmarshalYAML added in v0.6.0

func (t *Template) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements custom unmarshaling for Template. Accepts either a string (inline template) or an object with "file" field.

Jump to

Keyboard shortcuts

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