pkger/paths/paths_map.go

88 lines
1.7 KiB
Go

// Code generated by github.com/gobuffalo/mapgen. DO NOT EDIT.
package paths
import (
"sort"
"sync"
)
// pathsMap wraps sync.Map and uses the following types:
// key: string
// value: Path
type pathsMap struct {
data *sync.Map
}
// Delete the key from the map
func (m *pathsMap) Delete(key string) {
m.data.Delete(key)
}
// Load the key from the map.
// Returns Path or bool.
// A false return indicates either the key was not found
// or the value is not of type Path
func (m *pathsMap) Load(key string) (Path, bool) {
i, ok := m.data.Load(key)
if !ok {
return Path{}, false
}
s, ok := i.(Path)
return s, ok
}
// LoadOrStore will return an existing key or
// store the value if not already in the map
func (m *pathsMap) LoadOrStore(key string, value Path) (Path, bool) {
i, _ := m.data.LoadOrStore(key, value)
s, ok := i.(Path)
return s, ok
}
// LoadOr will return an existing key or
// run the function and store the results
func (m *pathsMap) LoadOr(key string, fn func(*pathsMap) (Path, bool)) (Path, bool) {
i, ok := m.Load(key)
if ok {
return i, ok
}
i, ok = fn(m)
if ok {
m.Store(key, i)
return i, ok
}
return i, false
}
// Range over the Path values in the map
func (m *pathsMap) Range(f func(key string, value Path) bool) {
m.data.Range(func(k, v interface{}) bool {
key, ok := k.(string)
if !ok {
return false
}
value, ok := v.(Path)
if !ok {
return false
}
return f(key, value)
})
}
// Store a Path in the map
func (m *pathsMap) Store(key string, value Path) {
m.data.Store(key, value)
}
// Keys returns a list of keys in the map
func (m *pathsMap) Keys() []string {
var keys []string
m.Range(func(key string, value Path) bool {
keys = append(keys, key)
return true
})
sort.Strings(keys)
return keys
}