2019-08-02 00:35:42 +03:00
|
|
|
// Code generated by github.com/gobuffalo/mapgen. DO NOT EDIT.
|
|
|
|
|
2019-08-02 05:34:32 +03:00
|
|
|
package pkger
|
2019-08-02 00:35:42 +03:00
|
|
|
|
|
|
|
import (
|
2019-08-03 23:36:56 +03:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2019-08-02 00:35:42 +03:00
|
|
|
"sort"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
// pathsMap wraps sync.Map and uses the following types:
|
|
|
|
// key: string
|
|
|
|
// value: Path
|
|
|
|
type pathsMap struct {
|
|
|
|
data *sync.Map
|
2019-08-03 23:36:56 +03:00
|
|
|
once *sync.Once
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *pathsMap) Data() *sync.Map {
|
|
|
|
if m.once == nil {
|
|
|
|
m.once = &sync.Once{}
|
|
|
|
}
|
|
|
|
m.once.Do(func() {
|
|
|
|
if m.data == nil {
|
|
|
|
m.data = &sync.Map{}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return m.data
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *pathsMap) MarshalJSON() ([]byte, error) {
|
|
|
|
mm := map[string]interface{}{}
|
|
|
|
m.Data().Range(func(key, value interface{}) bool {
|
|
|
|
mm[fmt.Sprintf("%s", key)] = value
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
return json.Marshal(mm)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *pathsMap) UnmarshalJSON(b []byte) error {
|
|
|
|
mm := map[string]Path{}
|
|
|
|
|
|
|
|
if err := json.Unmarshal(b, &mm); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for k, v := range mm {
|
|
|
|
m.Store(k, v)
|
|
|
|
}
|
|
|
|
return nil
|
2019-08-02 00:35:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete the key from the map
|
|
|
|
func (m *pathsMap) Delete(key string) {
|
2019-08-03 23:36:56 +03:00
|
|
|
m.Data().Delete(key)
|
2019-08-02 00:35:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2019-08-03 23:36:56 +03:00
|
|
|
i, ok := m.Data().Load(key)
|
2019-08-02 00:35:42 +03:00
|
|
|
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) {
|
2019-08-03 23:36:56 +03:00
|
|
|
i, _ := m.Data().LoadOrStore(key, value)
|
2019-08-02 00:35:42 +03:00
|
|
|
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) {
|
2019-08-03 23:36:56 +03:00
|
|
|
m.Data().Range(func(k, v interface{}) bool {
|
2019-08-02 00:35:42 +03:00
|
|
|
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) {
|
2019-08-03 23:36:56 +03:00
|
|
|
m.Data().Store(key, value)
|
2019-08-02 00:35:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|