// Code generated by github.com/gobuffalo/mapgen. DO NOT EDIT. package pkger import ( "encoding/json" "fmt" "sort" "sync" ) // pathsMap wraps sync.Map and uses the following types: // key: string // value: Path type pathsMap struct { data *sync.Map 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 } // 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 }