Store saves value at key.
(_ context.Context, key string, value []byte)
| 78 | |
| 79 | // Store saves value at key. |
| 80 | func (s *FileStorage) Store(_ context.Context, key string, value []byte) error { |
| 81 | filename := s.Filename(key) |
| 82 | err := os.MkdirAll(filepath.Dir(filename), 0700) |
| 83 | if err != nil { |
| 84 | return err |
| 85 | } |
| 86 | fp, err := atomicfile.New(filename, 0o600) |
| 87 | if err != nil { |
| 88 | return err |
| 89 | } |
| 90 | _, err = fp.Write(value) |
| 91 | if err != nil { |
| 92 | // cancel the write |
| 93 | fp.Cancel() |
| 94 | return err |
| 95 | } |
| 96 | // close, thereby flushing the write |
| 97 | return fp.Close() |
| 98 | } |
| 99 | |
| 100 | // Load retrieves the value at key. |
| 101 | func (s *FileStorage) Load(_ context.Context, key string) ([]byte, error) { |