Documentation ¶
Index ¶
- Constants
- func InitIocObject() error
- func ListApiObjectNames() (names []string)
- func ListControllerObjectNames() (names []string)
- func LoadGinApiObject(pathPrefix string, root gin.IRouter)
- func LoadGoRestfulApiObject(pathPrefix string, root *restful.Container)
- func LoadGrpcController(server *grpc.Server)
- func RegistryApiObject(obj ApiObject)
- func RegistryController(obj IocObject)
- func RegistryObject(obj IocObject)
- func RegistryObjectWithNamespace(namespace string, obj IocObject)
- type ApiObject
- type DefaultStore
- type GRPCController
- type GinApiObject
- type GoRestfulApiObject
- type IocObject
- type IocObjectImpl
- type IocObjectSet
- func (s *IocObjectSet) Add(obj IocObject)
- func (s *IocObjectSet) Exist(name string) bool
- func (s *IocObjectSet) Get(name string) IocObject
- func (s *IocObjectSet) Len() int
- func (s *IocObjectSet) Less(i, j int) bool
- func (s *IocObjectSet) ObjectNames() (names []string)
- func (s *IocObjectSet) Sort()
- func (s *IocObjectSet) Swap(i, j int)
Constants ¶
const ApiNamespace = "apis"
const ControllerNamespace = "controller"
const DefaultNamespace = "default"
Variables ¶
This section is empty.
Functions ¶
func InitIocObject ¶
func InitIocObject() error
InitIocObject initializes the default store for dependency injection Returns an error if the initialization fails
func ListApiObjectNames ¶
func ListApiObjectNames() (names []string)
func ListControllerObjectNames ¶
func ListControllerObjectNames() (names []string)
ListControllerObjectNames Returns a list of all IocObject names in the controller namespace.
func LoadGinApiObject ¶
func LoadGoRestfulApiObject ¶
func LoadGoRestfulApiObject(pathPrefix string, root *restful.Container)
func LoadGrpcController ¶
LoadGrpcController registers all objects to the gRPC server. It iterates over all objects in the controller namespace of the IOC container and attempts to cast them to the GRPCController interface type. If the object is a GRPCController, it is registered using the grpc server.
func RegistryApiObject ¶
func RegistryApiObject(obj ApiObject)
func RegistryController ¶
func RegistryController(obj IocObject)
RegistryController Registers an IocObject to the controller namespace. obj: The IocObject to be registered.
func RegistryObject ¶
func RegistryObject(obj IocObject)
RegistryObject registers an IocObject to the default namespace in the store. It is a shortcut function calling RegistryObjectWithNamespace with the default namespace.
obj: the IocObject to be registered.
func RegistryObjectWithNamespace ¶
RegistryObjectWithNamespace registers the given object to a specific namespace in the IOC container. It takes in a string representing the namespace and an IocObject interface representing the object to register.
Types ¶
type DefaultStore ¶
type DefaultStore struct {
// contains filtered or unexported fields
}
func NewDefaultStore ¶
func NewDefaultStore() *DefaultStore
NewDefaultStore creates a new DefaultStore
func (*DefaultStore) InitIocObject ¶
func (s *DefaultStore) InitIocObject() error
InitIocObject initializes all managed objects in the store. Returns an error if initialization of any object fails.
func (*DefaultStore) Namespace ¶
func (s *DefaultStore) Namespace(namespace string) *IocObjectSet
Namespace returns the IocObjectSet for the given namespace.
func (*DefaultStore) ShowRegisteredObjectNames ¶
func (s *DefaultStore) ShowRegisteredObjectNames() (names []string)
ShowRegisteredObjectNames returns the names of all managed objects in the store.
type GRPCController ¶
type GinApiObject ¶
type GoRestfulApiObject ¶
type GoRestfulApiObject interface { ApiObject Registry(*restful.WebService) }
type IocObject ¶
type IocObject interface { // Init initializes the object Init() error // Name returns the name of the object Name() string // Priority returns the priority of the object Priority() int }
func GetController ¶
GetController Returns an IocObject from the controller namespace with the given name.
func GetObjectWithNamespace ¶
GetObjectWithNamespace returns the object with the given namespace and name
type IocObjectImpl ¶
type IocObjectImpl struct { }
IocObjectImpl implements IocObject
func (*IocObjectImpl) Init ¶
func (i *IocObjectImpl) Init() error
Init initializes the IocObjectImpl object It returns an error if something goes wrong
func (*IocObjectImpl) Name ¶
func (i *IocObjectImpl) Name() string
Name returns the name of the object
func (*IocObjectImpl) Priority ¶
func (i *IocObjectImpl) Priority() int
Priority returns the priority of the object
type IocObjectSet ¶
type IocObjectSet struct {
Items []IocObject
}
IocObjectSet is a set of IocObject
func NewIocObjectSet ¶
func NewIocObjectSet() *IocObjectSet
NewIocObjectSet creates a new IocObjectSet
func (*IocObjectSet) Add ¶
func (s *IocObjectSet) Add(obj IocObject)
Add adds an IocObject to the IocObjectSet
func (*IocObjectSet) Exist ¶
func (s *IocObjectSet) Exist(name string) bool
Exist checks if the IocObjectSet has the given name.
func (*IocObjectSet) Get ¶
func (s *IocObjectSet) Get(name string) IocObject
Get returns the IocObjectSet object with the given name.
func (*IocObjectSet) Len ¶
func (s *IocObjectSet) Len() int
Len returns the length of the IocObjectSet
func (*IocObjectSet) Less ¶
func (s *IocObjectSet) Less(i, j int) bool
Less compares two elements of the IocObjectSet
func (*IocObjectSet) ObjectNames ¶
func (s *IocObjectSet) ObjectNames() (names []string)
ObjectNames returns the names of all registered IocObject
func (*IocObjectSet) Sort ¶
func (s *IocObjectSet) Sort()
Sort function sorts the IocObjectSet by object priority. It uses one call to data.Len to determine n and O(n*log(n)) calls to data.Less and data.Swap for sorting. The sort is not guaranteed to be stable.
func (*IocObjectSet) Swap ¶
func (s *IocObjectSet) Swap(i, j int)
Swap swaps two elements of the IocObjectSet