instance

package
v0.0.0-...-2910145 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package instance 提供了实例管理功能。

注意,此包并不用于缓存,因为它没有缓存过期机制。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear()

Clear 删除所有已存储的实例。

func Get

func Get(name string) interface{}

Get通过给定的名称返回实例。

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

func SetIfNotExist(name string, instance interface{}) bool

SetIfNotExist 如果`name`不存在,则将`instance`设置到map中,并返回true。 若`name`已存在,则返回false,同时`instance`将被忽略。

func X设置值

func X设置值(name string, instance interface{})

Set 将具有给定名称的实例设置到实例管理器中。

Types

This section is empty.

Jump to

Keyboard shortcuts

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