Documentation
¶
Overview ¶
Package instance 提供实例管理功能。
注意,此包不用于缓存,因为它没有缓存过期。 md5:9cde92d483190e72
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 Set(name string, instance interface{})
- func SetIfNotExist(name string, instance interface{}) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetOrSet ¶
func GetOrSet(name string, instance interface{}) interface{}
GetOrSet 通过名称获取实例, 如果不存在,则将其设置到实例管理器中并返回该实例。 md5:6e30e1788811bdcf
func GetOrSetFunc ¶
func GetOrSetFunc(name string, f func() interface{}) interface{}
GetOrSetFunc 通过名称获取实例, 如果不存在,它将使用回调函数 `f` 返回的值设置实例, 然后返回这个实例。 md5:3e2dff7c2a8267b6
func GetOrSetFuncLock ¶
func GetOrSetFuncLock(name string, f func() interface{}) interface{}
GetOrSetFuncLock 通过名称获取实例, 如果该实例不存在,则使用回调函数 `f` 的返回值设置实例, 并随后返回这个实例。
GetOrSetFuncLock 与 GetOrSetFunc 函数的不同之处在于, 它在执行函数 `f` 时会对哈希映射加锁(mutex.Lock)。 md5:d7adba14d37045fa
func SetIfNotExist ¶
SetIfNotExist 如果`name`不存在,则将`instance`设置到地图中,然后返回true。 如果`name`已经存在,则忽略`instance`并返回false。 md5:0eb14110f7286ae3
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.