injector

package
v4.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ValueTag is used to mark fields for automatic injection of config values.
	// Note: Unlike the autowire tag, it is only for injecting config values.
	// Example: `value:"${key:default}"`
	ValueTag = "value"

	// DecodeTag is used for mapstructure decoding of complex types (structs, maps, slices).
	// It allows both "mapstructure" and "json" tags to be used for field names.
	DecodeTag = "json,mapstructure"
)
View Source
const (
	AutowireTag = "autowire" // tag for autowiring fields
)

Variables

This section is empty.

Functions

func WireBean

func WireBean(bean any, fieldValue reflect.Value)

WireBean injects a bean into a struct field based on the provided field value.

func WireConfigValue

func WireConfigValue(cp config.Provider, fieldValue reflect.Value, expr ValueExpr) error

WireConfigValue looks up expr in cp and assigns the converted value to fieldValue. fieldValue must be addressable; unexported fields are supported.

Types

type ValueExpr added in v4.6.0

type ValueExpr struct {
	Key      string // Config key to look up
	Default  string // Fallback literal used when the key is absent; empty means "keep the zero value"
	Required bool   // Set by the "?" sentinel (`${key:?}`): an absent key fails start-up
}

ValueExpr is the parsed form of a `value:"${key:default}"` tag.

func ParseValueExpr added in v4.6.0

func ParseValueExpr(tag string) (ValueExpr, error)

ParseValueExpr parses a value tag of the form ${key}, ${key:default} or ${key:?}.

Jump to

Keyboard shortcuts

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