ioc

package module
v0.0.0-...-defed71 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigNamespace     = "configs"
	ControllerNamespace = "controllers"
	DefaultNamespace    = "default"
	ApiNamespace        = "apis"
)

Variables

This section is empty.

Functions

func ConfigIocObject

func ConfigIocObject(req *LoadConfigReq) error

ConfigIocObject 为容器中的对象进行二次配置

Types

type ConfigEnv

type ConfigEnv struct {
	Enabled bool
	Prefix  string
}

type ConfigFile

type ConfigFile struct {
	Enabled bool
	Path    string
}

type Container

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

Container 容器

func (*Container) Init

func (c *Container) Init()

func (*Container) Len

func (c *Container) Len() int

func (*Container) Less

func (c *Container) Less(i, j int) bool

func (*Container) LoadConfig

func (c *Container) LoadConfig(req *LoadConfigReq)

func (*Container) Namespace

func (c *Container) Namespace(ns string) *NamespaceStore

func (*Container) Swap

func (c *Container) Swap(i, j int)

type LoadConfigReq

type LoadConfigReq struct {
	ConfigFile *ConfigFile
	ConfigEnv  *ConfigEnv
}

LoadConfigReq 如何加载配置

type NamespaceInterface

type NamespaceInterface interface {
	Registry(obj ObjectInterface)    // 注册对象
	Get(name string) ObjectInterface // 获取对象
	List() []string                  // 打印对象名称列表
	LoadFromEnv(prefix string)       // 从环境变量中加载配置
	LoadFromFile(filename string)    // 从配置文件中加载
}

NamespaceInterface 容器接口约束

type NamespaceStore

type NamespaceStore struct {
	Namespace string
	Priority  int
	Items     []ObjectInterface
}

NamespaceStore 容器接口实现

func Api

func Api() *NamespaceStore

func Config

func Config() *NamespaceStore

func Controller

func Controller() *NamespaceStore

func Default

func Default() *NamespaceStore

func (*NamespaceStore) Close

func (s *NamespaceStore) Close(ctx context.Context) error

func (*NamespaceStore) Get

func (s *NamespaceStore) Get(name string) ObjectInterface

func (*NamespaceStore) Init

func (s *NamespaceStore) Init()

func (*NamespaceStore) Len

func (s *NamespaceStore) Len() int

func (*NamespaceStore) Less

func (s *NamespaceStore) Less(i, j int) bool

func (*NamespaceStore) List

func (s *NamespaceStore) List() []string

func (*NamespaceStore) LoadFromEnv

func (s *NamespaceStore) LoadFromEnv(prefix string)

LoadFromEnv 从环境比那里中加载对象配置,如果参数 prefix 为空,则以对象的大写名称作为前缀 CMDB_ ;否则以 PREFIX_CMDB 作为前缀进行解析,结果赋值给当前对象

func (*NamespaceStore) LoadFromFile

func (s *NamespaceStore) LoadFromFile(filename string)

LoadFromFile 从配置文件中加载对象配置

func (*NamespaceStore) Registry

func (s *NamespaceStore) Registry(o ObjectInterface)

func (*NamespaceStore) Swap

func (s *NamespaceStore) Swap(i, j int)

type ObjectImpl

type ObjectImpl struct {
}

func (*ObjectImpl) Close

func (o *ObjectImpl) Close(ctx context.Context) error

func (*ObjectImpl) Init

func (o *ObjectImpl) Init()

func (*ObjectImpl) Meta

func (o *ObjectImpl) Meta() ObjectMeta

func (*ObjectImpl) Name

func (o *ObjectImpl) Name() string

func (*ObjectImpl) Priority

func (o *ObjectImpl) Priority() int

type ObjectInterface

type ObjectInterface interface {
	Name() string                    // 对象名称
	Priority() int                   // 对象优先级
	Init()                           // 初始化对象
	Close(ctx context.Context) error // 关闭对象
	Meta() ObjectMeta                // 对象元数据描述信息,扩展使用
}

ObjectInterface 对象接口约束

type ObjectMeta

type ObjectMeta struct {
	PathPrefix string
	Extra      map[string]string
}

Jump to

Keyboard shortcuts

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