Documentation ¶
Index ¶
- func Add[T interface{}](scope ServiceScope, creator serverCreator[T])
- func AddCommand(cmd *cobra.Command)
- func AddCommandFunc(use string, short string, run func())
- func AddSingleton[T interface{}](creator serverCreator[T])
- func AddSingletonDefault[T interface{}]()
- func AddTransient[T interface{}](creator serverCreator[T])
- func AddTransientDefault[T interface{}]()
- func AddValue(value interface{})
- func Configure(action ConfigureFunc)
- func ConfigureOptions[T any](f func(container *Container, v *T))
- func Get[T interface{}]() *T
- func GetArray[T interface{}]() []T
- func GetByType[T interface{}](serviceType reflect.Type) *T
- func GetOptional[T interface{}]() (*T, bool)
- func GetPtr[T interface{}]() T
- func GetPtrOptional[T interface{}]() (T, bool)
- func Info(use string, short string, description string)
- func NewRun(r RunFunc) runFunInfo
- func OrderRun(order int, action RunFunc)
- func PostRun(action RunFunc)
- func Run(action RunFunc)
- func TryAdd[T interface{}](scope ServiceScope, creator serverCreator[T])
- func TryAddSingleton[T interface{}](creator serverCreator[T])
- func TryAddSingletonDefault[T interface{}]()
- func TryAddTransient[T interface{}](creator serverCreator[T])
- func TryAddTransientDefault[T interface{}]()
- func TryAddValue(value interface{})
- func Version(version string)
- type App
- type AppBuilder
- func (a *AppBuilder) Build() (*App, error)
- func (a *AppBuilder) Configure(action RunFunc)
- func (a *AppBuilder) Info(use string, short string, description string) *AppBuilder
- func (a *AppBuilder) OrderRun(order int, action RunFunc)
- func (a *AppBuilder) PostRun(action RunFunc)
- func (a *AppBuilder) Run(action RunFunc)
- func (a *AppBuilder) Version(version string) *AppBuilder
- type AppContext
- func (a *AppContext) OrderRun(order int, action RunFunc)
- func (a *AppContext) PostOrderRun(order int, action RunFunc)
- func (a *AppContext) PostRun(action RunFunc)
- func (a *AppContext) PreOrderRun(order int, action RunFunc)
- func (a *AppContext) PreRun(action RunFunc)
- func (a *AppContext) Run(action RunFunc)
- type AppEnvironment
- type AppOptions
- type CommandBuilder
- type ConfigureFunc
- type Container
- func (c *Container) Add(descriptor *ServiceDescriptor)
- func (c *Container) Configure(t reflect.Type, initFunc InitFunc)
- func (c *Container) Get(serviceType reflect.Type) interface{}
- func (c *Container) GetArray(baseType reflect.Type) []interface{}
- func (c *Container) GetOptional(serviceType reflect.Type) (interface{}, bool)
- func (c *Container) TryAdd(descriptor *ServiceDescriptor)
- type InitFunc
- type RunFunc
- type ServiceCreator
- type ServiceDescriptor
- type ServiceScope
- type VersionInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
func Add[T interface{}](scope ServiceScope, creator serverCreator[T])
func AddCommandFunc ¶
AddCommandFunc Add a command function to the application.
func AddSingleton ¶
func AddSingleton[T interface{}](creator serverCreator[T])
func AddSingletonDefault ¶
func AddSingletonDefault[T interface{}]()
AddSingletonDefault 添加 Singleton 无参构造对象
func AddTransient ¶
func AddTransient[T interface{}](creator serverCreator[T])
func AddTransientDefault ¶
func AddTransientDefault[T interface{}]()
AddTransientDefault 添加Transient无参构造对象
func Configure ¶
func Configure(action ConfigureFunc)
Configure is a function that will be called before the application run.
func ConfigureOptions ¶
ConfigureOptions 配置 Options,不支持两个类型相互依赖
func GetOptional ¶
func GetOptional[T interface{}]() (*T, bool)
func GetPtrOptional ¶
func GetPtrOptional[T interface{}]() (T, bool)
func OrderRun ¶
OrderRun is a function that will be called by order when the application starts run.
func PostRun ¶
func PostRun(action RunFunc)
PostRun is a function that will be called before the application exit.
func Run ¶
func Run(action RunFunc)
Run is a function that will be called when the application starts run. order is 0.
func TryAdd ¶
func TryAdd[T interface{}](scope ServiceScope, creator serverCreator[T])
func TryAddSingleton ¶
func TryAddSingleton[T interface{}](creator serverCreator[T])
func TryAddSingletonDefault ¶
func TryAddSingletonDefault[T interface{}]()
TryAddSingletonDefault 添加 Singleton 无参构造对象
func TryAddTransient ¶
func TryAddTransient[T interface{}](creator serverCreator[T])
func TryAddTransientDefault ¶
func TryAddTransientDefault[T interface{}]()
TryAddTransientDefault 添加Transient无参构造对象
func TryAddValue ¶
func TryAddValue(value interface{})
Types ¶
type AppBuilder ¶
type AppBuilder struct { Context *AppContext CmdBuilder *CommandBuilder }
func DefaultBuilder ¶
func DefaultBuilder() *AppBuilder
func NewAppBuilder ¶
func NewAppBuilder() *AppBuilder
func (*AppBuilder) Build ¶
func (a *AppBuilder) Build() (*App, error)
func (*AppBuilder) Configure ¶
func (a *AppBuilder) Configure(action RunFunc)
func (*AppBuilder) Info ¶
func (a *AppBuilder) Info(use string, short string, description string) *AppBuilder
func (*AppBuilder) OrderRun ¶
func (a *AppBuilder) OrderRun(order int, action RunFunc)
func (*AppBuilder) PostRun ¶
func (a *AppBuilder) PostRun(action RunFunc)
func (*AppBuilder) Run ¶
func (a *AppBuilder) Run(action RunFunc)
func (*AppBuilder) Version ¶
func (a *AppBuilder) Version(version string) *AppBuilder
type AppContext ¶
type AppContext struct { PreRuns []runFunInfo Runs []runFunInfo PostRuns []runFunInfo Name string Short string Description string Version string }
func NewAppContext ¶
func NewAppContext() *AppContext
func (*AppContext) OrderRun ¶
func (a *AppContext) OrderRun(order int, action RunFunc)
func (*AppContext) PostOrderRun ¶
func (a *AppContext) PostOrderRun(order int, action RunFunc)
func (*AppContext) PostRun ¶
func (a *AppContext) PostRun(action RunFunc)
func (*AppContext) PreOrderRun ¶
func (a *AppContext) PreOrderRun(order int, action RunFunc)
func (*AppContext) PreRun ¶
func (a *AppContext) PreRun(action RunFunc)
func (*AppContext) Run ¶
func (a *AppContext) Run(action RunFunc)
type AppEnvironment ¶
type AppEnvironment string
const ( Development AppEnvironment = "development" Production AppEnvironment = "production" Staging AppEnvironment = "staging" )
type AppOptions ¶
type AppOptions struct { Environment AppEnvironment LogLevel zerolog.Level }
type CommandBuilder ¶
func NewCommandBuilder ¶
func NewCommandBuilder() *CommandBuilder
func (*CommandBuilder) AddCommand ¶
func (b *CommandBuilder) AddCommand(cmd *cobra.Command)
func (*CommandBuilder) AddRun ¶
func (b *CommandBuilder) AddRun(use string, short string, run func())
func (*CommandBuilder) Build ¶
func (cb *CommandBuilder) Build(ac *AppContext) (*cobra.Command, error)
type ConfigureFunc ¶
type ConfigureFunc = func() error
type Container ¶
type Container struct { Services []*serviceItem // contains filtered or unexported fields }
func AddService ¶
func AddService(descriptor *ServiceDescriptor) *Container
func CreateContainer ¶
func CreateContainer() *Container
func GetContainer ¶
func GetContainer() *Container
func TryAddService ¶
func TryAddService(descriptor *ServiceDescriptor) *Container
func (*Container) Add ¶
func (c *Container) Add(descriptor *ServiceDescriptor)
func (*Container) GetOptional ¶
GetOptional 获取对象,如果没有,返回nil
func (*Container) TryAdd ¶
func (c *Container) TryAdd(descriptor *ServiceDescriptor)
type ServiceCreator ¶
type ServiceCreator func(c *Container) interface{}
type ServiceDescriptor ¶
type ServiceDescriptor struct { ServiceType reflect.Type Creator ServiceCreator Scope ServiceScope Value interface{} }
func NewServiceDescriptor ¶
func NewServiceDescriptor(serviceType reflect.Type, creator ServiceCreator, scope ServiceScope) ServiceDescriptor
type ServiceScope ¶
type ServiceScope int
const ( Transient ServiceScope = 0 Singleton ServiceScope = 1 Scoped ServiceScope = 2 )
type VersionInfo ¶
func (*VersionInfo) String ¶
func (v *VersionInfo) String() string
Click to show internal directories.
Click to hide internal directories.