ioc

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ApiNamespace = "apis"
View Source
const ControllerNamespace = "controller"
View Source
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 LoadGinApiObject(pathPrefix string, root gin.IRouter)

func LoadGoRestfulApiObject

func LoadGoRestfulApiObject(pathPrefix string, root *restful.Container)

func LoadGrpcController

func LoadGrpcController(server *grpc.Server)

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

func RegistryObjectWithNamespace(namespace string, obj IocObject)

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 ApiObject

type ApiObject interface {
	IocObject
	Version() string
}

HTTPService Http服务的实例

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 GRPCController interface {
	Registry(*grpc.Server)
}

type GinApiObject

type GinApiObject interface {
	ApiObject
	Registry(gin.IRouter)
}

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 GetApi

func GetApi(name string) IocObject

func GetController

func GetController(name string) IocObject

GetController Returns an IocObject from the controller namespace with the given name.

func GetObject

func GetObject(name string) IocObject

GetObject returns the object with the given name, default namespace is used.

func GetObjectWithNamespace

func GetObjectWithNamespace(namespace string, name string) IocObject

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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