blob: 7242d8eb7afe6ad0888b3c0c76f79ea3d0dcbe8f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package service
import (
"context"
"errors"
"github.com/RanXom/galleryd/internal/gallery"
)
var ErrPhotoNotFound = errors.New("photo not found")
// Photo returns a single photo by its ID.
func (s *galleryService) Photo(
ctx context.Context,
id string,
) (gallery.Photo, error) {
s.mu.RLock()
defer s.mu.RUnlock()
select {
case <-ctx.Done():
return gallery.Photo{}, ctx.Err()
default:
}
photo, ok := s.index.byID[id]
if !ok {
return gallery.Photo{}, ErrPhotoNotFound
}
return photo, nil
}
|