factory

package module
v0.0.0-...-55984ea Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MIT Imports: 16 Imported by: 11

Documentation

Index

Constants

View Source
const DefaultInitMethodName = "Init"

DefaultInitMethodName is a constant representing the default name of the initialization method. It is used in the NewWithOption function to determine the name of the method to invoke during initialization. If the 'initMethodName' field in the Option struct is empty, the DefaultInitMethodName is used. If the 'useConstructor' field in the Option struct is true, the DefaultInitMethodName is set to the name of the struct. The DefaultInitMethodName is used in reflection to find and invoke the initialization method.

View Source
const GetterKey = "Getter"
View Source
const NewMethodName = "New"
View Source
const TimeoutKey = "Timeout"
View Source
const TypeKey = "type"

Variables

View Source
var ErrInvalidTag = errors.New("not a valid Tag")
View Source
var ErrInvalidWireValue = errors.New("not a valid WireValue")
View Source
var Opts = struct {
	EnableTimeout   bool
	Timeout         time.Duration
	TimeoutInterval time.Duration
	Log             Logger
}{
	EnableTimeout:   false,
	Timeout:         3 * time.Second,
	TimeoutInterval: 100 * time.Millisecond,
	Log:             &logger{},
}

Functions

func AutoWire

func AutoWire(self any) error

func AutoWireTimeout

func AutoWireTimeout(self any, timeout time.Duration) error

func Factory

func Factory[T any](f any) *_factory

func FactoryWithType

func FactoryWithType(vt reflect.Type, f any) *_factory

func Find

func Find[T any]() *T

func FindByName

func FindByName[T any](name string) *T

func FindByNameTimeout

func FindByNameTimeout[T any](name string, timeout time.Duration) *T

func FindInterfaces

func FindInterfaces[T any]() (result []T)

func FindStructs

func FindStructs[T any]() (result []*T)

func FindTimeout

func FindTimeout[T any](timeout time.Duration) *T

func Get

func Get[T any]() *T

func Getter

func Getter[T any](s *singleton) func() *T

func IGetter

func IGetter[T any](s *iInterface) func() T

func Interface

func Interface[T any]() *iInterface

func NamedInterface

func NamedInterface[T any](name string) *iInterface

func NamedSingleton

func NamedSingleton[T any](name string) *singleton

func New

func New[T any]() *T

func NewBeforeInit

func NewBeforeInit[T any](f func(*T)) *T

func NewBeforeInitOption

func NewBeforeInitOption[T any](f func(*T), option *Option) *T

func NewWithOption

func NewWithOption[T any](option *Option) *T

func Put

func Put[T any](t *T)

func Range

func Range[T any](rangeFunc func(any) bool)

func RangeInterface

func RangeInterface[T any](interfaceFunc func(T) bool)

func RangeStruct

func RangeStruct[T any](structFunc func(*T) bool)

func RangeTimeout

func RangeTimeout[T any](rangeFunc func(any) bool, timeout time.Duration)

func SetPoolInit

func SetPoolInit[T any](option *Option)

func Singleton

func Singleton[T any]() *singleton

Types

type Error

type Error struct {
	Errors []string
}

copied from github.com/mitchellh/mapstructure Error implements the error interface and can represents multiple errors that occur in the course of a single Decode.

func (*Error) Error

func (e *Error) Error() string

func (*Error) WrappedErrors

func (e *Error) WrappedErrors() []error

WrappedErrors implements the errwrap.Wrapper interface to make this return value more useful with the errwrap and go-multierror libraries.

type Logger

type Logger interface {
	Debugf(template string, args ...any)
}

type Option

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

func NewOption

func NewOption() *Option

func (*Option) InitMethodName

func (o *Option) InitMethodName(initMethodName string) *Option

func (*Option) InitParams

func (o *Option) InitParams(initParams ...string) *Option

func (*Option) UseConstructor

func (o *Option) UseConstructor(useConstructor bool) *Option

type Tag

type Tag string

Tag is an enum @Enum{wire, value, new}

const (
	// TagWire is a Tag of type wire.
	TagWire Tag = "wire"
	// TagValue is a Tag of type value.
	TagValue Tag = "value"
	// TagNew is a Tag of type new.
	TagNew Tag = "new"
)

func ParseTag

func ParseTag(value string) (Tag, error)

ParseTag converts a string to a Tag.

func (Tag) IsValid

func (x Tag) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (Tag) Name

func (x Tag) Name() string

Name is the attribute of Tag.

func (Tag) String

func (x Tag) String() string

String implements the Stringer interface.

func (Tag) Val

func (x Tag) Val() string

Val is the attribute of Tag.

type TagWithValue

type TagWithValue struct {
	Tag   WireValue
	Value string
}

func ParseTagValue

func ParseTagValue(tagValue string, checkAndSet func(tv *TagWithValue)) (tv *TagWithValue, err error)

func (*TagWithValue) String

func (tv *TagWithValue) String() string

type WireValue

type WireValue string

WireValue is an enum @EnumConfig(marshal, values, noComments, noCase) @Enum{self, auto, type, name, value}

const (
	WireValueSelf  WireValue = "self"
	WireValueAuto  WireValue = "auto"
	WireValueType  WireValue = "type"
	WireValueName  WireValue = "name"
	WireValueValue WireValue = "value"
)

func ParseWireValue

func ParseWireValue(value string) (WireValue, error)

ParseWireValue converts a string to a WireValue.

func WireValueValues

func WireValueValues() []WireValue

WireValueValues returns a list of the values of WireValue

func (WireValue) IsValid

func (x WireValue) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (WireValue) MarshalText

func (x WireValue) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (WireValue) Name

func (x WireValue) Name() string

Name is the attribute of WireValue.

func (WireValue) String

func (x WireValue) String() string

String implements the Stringer interface.

func (*WireValue) UnmarshalText

func (x *WireValue) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

func (WireValue) Val

func (x WireValue) Val() string

Val is the attribute of WireValue.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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