github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/base/bobjectstorage/README.md (about) 1 # bobjectstorage 2 3 ## API 4 5 - Set 6 - GetSafeAssertion 7 - Get 8 9 ## EXAMPLE 10 11 ```go 12 package main 13 14 import ( 15 "fmt" 16 "github.com/songzhibin97/go-baseutils/base/bobjectstorage" 17 ) 18 19 type mock struct { 20 } 21 22 func (t mock) Test() string { 23 return "test" 24 } 25 26 func main() { 27 mc := mock{} 28 bobjectstorage.Set("key1", "string") 29 bobjectstorage.Set("key2", 1) 30 bobjectstorage.Set("key3", mc) 31 fmt.Println(bobjectstorage.Get[string]("key1")) // "string" 32 fmt.Println(bobjectstorage.Get[string]("key2")) // 1 33 fmt.Println(bobjectstorage.Get[mock]("key3")) // mock obj 34 fmt.Println(bobjectstorage.Get[*mock]("key4")) // mock point obj 35 } 36 37 ```