MCPcopy Create free account
hub / github.com/cloudwan/gohan / Get

Function Get

singleton/singleton.go:56–66  ·  view source on GitHub ↗

Get returns singleton for a given key, value does not exist if will be created by factory.

(key string, factory func() interface{})

Source from the content-addressed store, hash-verified

54// Get returns singleton for a given key, value does not exist if will be
55// created by factory.
56func Get(key string, factory func() interface{}) interface{} {
57 mu.Lock()
58 defer mu.Unlock()
59
60 v := c.Get(key)
61 if v == nil {
62 v = factory()
63 c.Set(key, v)
64 }
65 return v
66}
67
68// Clear removes singleton for a given key.
69func Clear(key string) {

Callers

nothing calls this directly

Calls 4

LockMethod · 0.65
UnlockMethod · 0.65
GetMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected