godi

package module
v0.0.0-...-0574c50 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2021 License: MIT Imports: 11 Imported by: 0

README

godi

Documentation

Index

Constants

View Source
const (
	Singleton provideScope = iota
	Prototype
)
View Source
const (
	Normal       provideType = 0
	Preloadable  provideType = 1
	Shutdownable provideType = 2
	Runnable     provideType = 4
	Service                  = Preloadable | Runnable | Shutdownable
)
View Source
const (
	DefaultTag = "default"
)

Variables

View Source
var (
	PacketNotFound           = errors.New("packet not found")
	VariableIsNotPtr         = errors.New("retrieve variable must be pointer")
	VariableIsNotSlice       = errors.New("retrieve variable must be slice")
	VariableIsNotMap         = errors.New("retrieve variable must be map")
	ValueIsNotPtrOrInterface = errors.New("value must be pointer or interface")
	InvalidConstructor       = errors.New("invalid godi constructor")
	InvalidDependencies      = errors.New("invalid dependencies")
	ContainerIsNotRunning    = errors.New("Container not running")
	ContainerInRunning       = errors.New("Container running")
	ProviderNotFound         = errors.New("provider not found")
)

Functions

func InstanceOf

func InstanceOf(value interface{}, filters ...string) error

func MapOf

func MapOf(value interface{}, filters ...string) error

func Register

func Register(constructor interface{}, opts ...RegisterOption) error

func Run

func Run()

func SetLogger

func SetLogger(logger Logger)

func SliceOf

func SliceOf(value interface{}, filters ...string) error

func Trigger

func Trigger(callback func()) error

func TypeOf

func TypeOf(value interface{}) string

func TypeOfPtr

func TypeOfPtr(value interface{}) string

func Unregister

func Unregister(packetName string, tags ...string)

Types

type Container

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

func GetApplicationContainer

func GetApplicationContainer() *Container

func (*Container) Context

func (c *Container) Context() ContainerContext

func (*Container) InstanceOf

func (c *Container) InstanceOf(value interface{}, filters []string) error

func (*Container) Log

func (c *Container) Log() Logger

func (*Container) MapOf

func (c *Container) MapOf(value interface{}, filters []string) error

func (*Container) Register

func (c *Container) Register(constructor interface{}, opts []RegisterOption) error

func (*Container) Run

func (c *Container) Run()

func (*Container) SetLogger

func (c *Container) SetLogger(logger Logger)

func (*Container) SliceOf

func (c *Container) SliceOf(value interface{}, filters []string) error

func (*Container) Trigger

func (c *Container) Trigger(callback func()) error

func (*Container) Unregister

func (c *Container) Unregister(packetName string, tags []string)

unregister all if tags = nil

type ContainerContext

type ContainerContext interface {
	context.Context
	Log() Logger
	State() ContainerState
	Retrievable() bool
	ShutDown()
}

func GetContext

func GetContext() ContainerContext

type ContainerState

type ContainerState uint
const (
	Initializing ContainerState = iota
	ContainerRunning
	ContainerShutdown
)

func (ContainerState) Name

func (c ContainerState) Name() string

type Context

type Context interface {
	context.Context
	Container() ContainerContext
	State() ServiceState
	Log() Logger
}

type Logger

type Logger interface {
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	Panic(args ...interface{})
	Debugf(template string, args ...interface{})
	Infof(template string, args ...interface{})
	Warnf(template string, args ...interface{})
	Errorf(template string, args ...interface{})
	Panicf(template string, args ...interface{})
}

func Log

func Log() Logger

type PreLoader

type PreLoader interface {
	Preload(ctx Context)
}

type RegisterOption

type RegisterOption func(option *registerOption)

func Filter

func Filter(dependency string, tags ...string) RegisterOption

func Scope

func Scope(scope provideScope) RegisterOption

func Tag

func Tag(tag string) RegisterOption

func Type

func Type(types ...provideType) RegisterOption

type Runner

type Runner interface {
	Run(ctx Context) error
}

type ServiceState

type ServiceState uint
const (
	ServiceInitialize ServiceState = 0
	ServicePreloading ServiceState = 1
	ServiceRunning    ServiceState = 2
	ServiceShutDown   ServiceState = 4
)

type ShutDowner

type ShutDowner interface {
	ShutDown(ctx Context)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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