1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-27 13:55:56 +00:00
Former-commit-id: 4c71a275f3e10dd0ce77bf5723c370be765663ab
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-03 13:48:34 +03:00
parent beb3f730a0
commit 8c3e43df7f
3 changed files with 77 additions and 6 deletions

View File

@@ -815,6 +815,19 @@ func (r *Store) Get(key string) interface{} {
return r.GetDefault(key, nil)
}
// GetOrSet is like `GetDefault` but it accepts a function which is
// fired and its result is used to `Set` if
// the "key" was not found or its value is nil.
func (r *Store) GetOrSet(key string, setFunc func() interface{}) interface{} {
if v, ok := r.GetEntry(key); ok && v.ValueRaw != nil {
return v.Value()
}
value := setFunc()
r.Set(key, value)
return value
}
// Visit accepts a visitor which will be filled
// by the key-value objects.
func (r *Store) Visit(visitor func(key string, value interface{})) {