dixinternal

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultProviderTimeout is the default max execution time for a single provider call.
	// Set WithProviderTimeout(0) to disable timeout control.
	DefaultProviderTimeout = 15 * time.Second

	// DefaultSlowProviderThreshold is the default warning threshold for provider execution latency.
	// Set WithSlowProviderThreshold(0) to disable slow-provider warnings.
	DefaultSlowProviderThreshold = 2 * time.Second
)
View Source
const (

	// InjectMethodPrefix can inject objects, as long as the method of this object contains a prefix of `InjectMethodPrefix`
	InjectMethodPrefix = "DixInject"
)

Variables

This section is empty.

Functions

func GetFnName

func GetFnName(fn reflect.Value) string

GetFnName returns the name of the function represented by reflect.Value

func GetFnTraceName

func GetFnTraceName(fn reflect.Value) string

GetFnTraceName returns function name for trace logs with best-effort full package path. For normal packages runtime already returns full import path. For `main.*` symbols, this attempts to rebuild a module-qualified path from source file location.

func GetProvideAllInputTypes

func GetProvideAllInputTypes(typ reflect.Type) []reflect.Type

GetProvideAllInputTypes returns all input types for a given type, including struct fields This is a public version of getProvideAllInputs that returns types instead of internal structures

func SetLog

func SetLog(handler slog.Handler)

Types

type DiagFileQuery

type DiagFileQuery struct {
	Kind      string
	Event     string
	Search    string
	Limit     int
	BeforeID  int64
	SinceUnix int64
	UntilUnix int64
}

DiagFileQuery controls filtering and pagination for DIX_DIAG_FILE records.

type DiagFileReadResult

type DiagFileReadResult struct {
	Enabled    bool             `json:"enabled"`
	Path       string           `json:"path,omitempty"`
	Exists     bool             `json:"exists"`
	Total      int              `json:"total"`
	Returned   int              `json:"returned"`
	NextBefore int64            `json:"next_before_id,omitempty"`
	Records    []DiagFileRecord `json:"records"`
}

DiagFileReadResult is the API response object for diagnostic file queries.

func ReadDiagFileRecords

func ReadDiagFileRecords(query DiagFileQuery) (DiagFileReadResult, error)

ReadDiagFileRecords loads and filters records from DIX_DIAG_FILE.

func ReadDiagFileRecordsFromLines

func ReadDiagFileRecordsFromLines(lines []string, query DiagFileQuery) DiagFileReadResult

ReadDiagFileRecordsFromLines is a test helper for parsing query behavior without I/O.

type DiagFileRecord

type DiagFileRecord struct {
	RecordID    int64          `json:"record_id,omitempty"`
	Source      string         `json:"source,omitempty"`
	PID         int            `json:"pid,omitempty"`
	Process     string         `json:"process,omitempty"`
	Hostname    string         `json:"hostname,omitempty"`
	TraceDI     bool           `json:"trace_di,omitempty"`
	LLMDiagMode string         `json:"llm_diag_mode,omitempty"`
	Kind        string         `json:"kind"`
	OccurredAt  int64          `json:"occurred_at_unix_nano"`
	Event       string         `json:"event,omitempty"`
	Fields      map[string]any `json:"fields,omitempty"`
	Payload     any            `json:"payload,omitempty"`
}

DiagFileRecord is an exported diagnostic record returned by file-query APIs.

type Dix

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

func New

func New(opts ...Option) *Dix

New Dix new

func (*Dix) GetObjects

func (dix *Dix) GetObjects() map[reflect.Type]map[string][]reflect.Value

GetObjects returns a copy of the objects map for inspection This is useful for HTTP visualization endpoints

func (*Dix) GetProviderDetails

func (dix *Dix) GetProviderDetails() []ProviderDetails

GetProviderDetails returns detailed information about all providers

func (*Dix) GetProviderRuntimeStats

func (dix *Dix) GetProviderRuntimeStats() []ProviderRuntimeStats

GetProviderRuntimeStats returns runtime stats sorted by total duration (descending). This is helpful for startup latency diagnosis.

func (*Dix) GetProviders

func (dix *Dix) GetProviders() map[reflect.Type][]*providerFn

GetProviders returns a copy of the providers map for inspection This is useful for HTTP visualization endpoints

func (*Dix) GetRecentErrors

func (dix *Dix) GetRecentErrors(limit int) []RecentError

GetRecentErrors returns recent Inject/TryInject errors in reverse-chronological order. limit <= 0 means return all currently retained errors.

func (*Dix) Inject

func (dix *Dix) Inject(param any, opts ...Option) any

Inject injects dependencies into the given parameter. Panics on error. NOTE: Dix container is not thread-safe. Do not call Provide/Inject concurrently on the same container.

func (*Dix) InjectContext

func (dix *Dix) InjectContext(ctx context.Context, param any, opts ...Option) any

InjectContext injects dependencies using the provided context as trace propagation root. Panics on error. NOTE: Dix container is not thread-safe. Do not call Provide/Inject concurrently on the same container.

func (*Dix) Option

func (dix *Dix) Option() Options

func (*Dix) Provide

func (dix *Dix) Provide(param any)

Provide registers a provider function. Panics on error. NOTE: Dix container is not thread-safe. Do not call Provide/Inject concurrently on the same container.

func (*Dix) TryInject

func (dix *Dix) TryInject(param any, opts ...Option) error

TryInject injects dependencies into the given parameter. Returns error instead of panicking. NOTE: Dix container is not thread-safe. Do not call Provide/Inject concurrently on the same container.

func (*Dix) TryInjectContext

func (dix *Dix) TryInjectContext(ctx context.Context, param any, opts ...Option) error

TryInjectContext injects dependencies using the provided context as trace propagation root. Returns error instead of panicking. NOTE: Dix container is not thread-safe. Do not call Provide/Inject concurrently on the same container.

func (*Dix) TryProvide

func (dix *Dix) TryProvide(param any) (err error)

TryProvide registers a provider function. Returns error instead of panicking. NOTE: Dix container is not thread-safe. Do not call Provide/Inject concurrently on the same container.

type Option

type Option func(opts *Options)

func WithProviderTimeout

func WithProviderTimeout(timeout time.Duration) Option

func WithSlowProviderThreshold

func WithSlowProviderThreshold(threshold time.Duration) Option

func WithValuesNull

func WithValuesNull() Option

type Options

type Options struct {
	// AllowValuesNull allows result to be nil
	AllowValuesNull bool

	// ProviderTimeout limits the maximum execution time of one provider call.
	// Zero means no timeout.
	ProviderTimeout time.Duration

	// SlowProviderThreshold emits warning log if provider execution is slower than this threshold.
	// Zero means no slow-warning threshold.
	SlowProviderThreshold time.Duration
}

func (Options) Merge

func (o Options) Merge(opt Options) Options

func (Options) Validate

func (o Options) Validate() error

type ProviderDetails

type ProviderDetails struct {
	OutputType   string
	OutputPkg    string
	FunctionName string
	FunctionPkg  string
	FunctionFile string
	FunctionLine int
	InputTypes   []string
	InputPkgs    []string
}

ProviderDetails contains detailed information about a provider

type ProviderRuntimeStats

type ProviderRuntimeStats struct {
	FunctionName      string        `json:"function_name"`
	OutputType        string        `json:"output_type"`
	CallCount         int           `json:"call_count"`
	TotalDuration     time.Duration `json:"total_duration"`
	AverageDuration   time.Duration `json:"average_duration"`
	LastDuration      time.Duration `json:"last_duration"`
	LastError         string        `json:"last_error,omitempty"`
	LastRunAtUnixNano int64         `json:"last_run_at_unix_nano"`
}

ProviderRuntimeStats contains provider runtime metrics for diagnostics.

type RecentError

type RecentError struct {
	Operation          string        `json:"operation"`
	ErrorType          string        `json:"error_type,omitempty"`
	Component          string        `json:"component"`
	Stage              string        `json:"stage,omitempty"`
	ProviderFunction   string        `json:"provider_function,omitempty"`
	OutputType         string        `json:"output_type,omitempty"`
	InputType          string        `json:"input_type,omitempty"`
	InputTypes         []string      `json:"input_types,omitempty"`
	Message            string        `json:"message"`
	RootCause          string        `json:"root_cause,omitempty"`
	Hint               string        `json:"hint,omitempty"`
	TimedOut           bool          `json:"timed_out,omitempty"`
	Duration           time.Duration `json:"duration,omitempty"`
	Timeout            time.Duration `json:"timeout,omitempty"`
	OccurredAtUnixNano int64         `json:"occurred_at_unix_nano"`
}

RecentError contains a recently captured Inject/TryInject failure event.

Jump to

Keyboard shortcuts

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