instance

package
v0.0.0-...-c4191a4 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package instance provides instances management.

Note that this package is not used for cache, as it has no cache expiration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear()

Clear deletes all instances stored.

func Get

func Get(name string) interface{}

Get returns the instance by given name.

func GetOrSet

func GetOrSet(name string, instance interface{}) interface{}

GetOrSet returns the instance by name, or set instance to the instance manager if it does not exist and returns this instance.

func GetOrSetFunc

func GetOrSetFunc(name string, f func() interface{}) interface{}

GetOrSetFunc returns the instance by name, or sets instance with returned value of callback function `f` if it does not exist and then returns this instance.

func GetOrSetFuncLock

func GetOrSetFuncLock(name string, f func() interface{}) interface{}

GetOrSetFuncLock returns the instance by name, or sets instance with returned value of callback function `f` if it does not exist and then returns this instance.

GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function `f` with mutex.Lock of the hash map.

func Set

func Set(name string, instance interface{})

Set sets an instance to the instance manager with given name.

func SetIfNotExist

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

SetIfNotExist sets `instance` to the map if the `name` does not exist, then returns true. It returns false if `name` exists, and `instance` would be ignored.

Types

This section is empty.

Jump to

Keyboard shortcuts

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