forked from kosa3/pexels-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_service.go
44 lines (35 loc) · 1.18 KB
/
video_service.go
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
33
34
35
36
37
38
39
40
41
42
43
44
package pexels
import (
"context"
"fmt"
"strconv"
)
type VideoService interface {
Search(ctx context.Context, params *VideoParams) (*SearchVideoResponse, error)
Popular(ctx context.Context, params *PopularParams) (*PopularVideoResponse, error)
Find(ctx context.Context, videoId int) (*Video, error)
}
type videoService struct {
cli *Client
}
func (s *videoService) Search(ctx context.Context, params *VideoParams) (*SearchVideoResponse, error) {
var sv SearchVideoResponse
if err := s.cli.get(ctx, "videos/search", StructToMap(params), &sv); err != nil {
return nil, fmt.Errorf("GET search failed: %w", err)
}
return &sv, nil
}
func (s *videoService) Popular(ctx context.Context, params *PopularParams) (*PopularVideoResponse, error) {
var pr PopularVideoResponse
if err := s.cli.get(ctx, "videos/popular", StructToMap(params), &pr); err != nil {
return nil, fmt.Errorf("GET popular failed: %w", err)
}
return &pr, nil
}
func (s *videoService) Find(ctx context.Context, videoId int) (*Video, error) {
var v Video
if err := s.cli.get(ctx, "videos/videos/"+strconv.Itoa(videoId), nil, &v); err != nil {
return nil, fmt.Errorf("GET videos failed: %w", err)
}
return &v, nil
}