Documentation ¶
Overview ¶
Package instance 提供了实例管理功能。
注意,此包并不用于缓存,因为它没有缓存过期机制。
Index ¶
- func Clear()
- func Get(name string) interface{}
- func GetOrSet(name string, instance interface{}) interface{}
- func GetOrSetFunc(name string, f func() interface{}) interface{}
- func GetOrSetFuncLock(name string, f func() interface{}) interface{}
- func SetIfNotExist(name string, instance interface{}) bool
- func X设置值(name string, instance interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetOrSet ¶
func GetOrSet(name string, instance interface{}) interface{}
GetOrSet 函数通过名称获取实例, 如果实例不存在,则将其设置到实例管理器中并返回该实例。
func GetOrSetFunc ¶
func GetOrSetFunc(name string, f func() interface{}) interface{}
GetOrSetFunc 函数通过名称返回实例, 如果实例不存在,则使用回调函数 `f` 返回的值设置该实例, 然后返回这个已设置的实例。
func GetOrSetFuncLock ¶
func GetOrSetFuncLock(name string, f func() interface{}) interface{}
GetOrSetFuncLock 通过名称返回实例, 如果实例不存在,则使用回调函数 `f` 返回的值设置该实例, 然后返回这个实例。
GetOrSetFuncLock 与 GetOrSetFunc 函数的不同之处在于, 它在哈希映射的 mutex.Lock 保护下执行函数 `f`。
func SetIfNotExist ¶
SetIfNotExist 如果`name`不存在,则将`instance`设置到map中,并返回true。 若`name`已存在,则返回false,同时`instance`将被忽略。
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.