loadFromFile decodes path into entries. A missing file is not an error and leaves entries empty.
(path string, entries map[string]string)
| 259 | // loadFromFile decodes path into entries. A missing file is not an error |
| 260 | // and leaves entries empty. |
| 261 | func loadFromFile(path string, entries map[string]string) error { |
| 262 | data, err := os.ReadFile(path) |
| 263 | switch { |
| 264 | case errors.Is(err, os.ErrNotExist): |
| 265 | return nil |
| 266 | case err != nil: |
| 267 | return fmt.Errorf("reading cache file %q: %w", path, err) |
| 268 | } |
| 269 | if len(data) == 0 { |
| 270 | return nil |
| 271 | } |
| 272 | if err := json.Unmarshal(data, &entries); err != nil { |
| 273 | return fmt.Errorf("loading cache file %q: %w", path, err) |
| 274 | } |
| 275 | return nil |
| 276 | } |
| 277 | |
| 278 | // mtimeOf returns the file modification time at path, or the zero value |
| 279 | // if path doesn't exist or can't be stat'd. |
no test coverage detected