forked from nytimes/gizmo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mostpopular.go
38 lines (33 loc) · 961 Bytes
/
mostpopular.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
package service
import (
"net/http"
"github.com/NYTimes/gizmo/examples/nyt"
"github.com/NYTimes/gizmo/server"
"github.com/NYTimes/gizmo/web"
"golang.org/x/net/context"
)
func (s *RPCService) GetMostPopular(ctx context.Context, r *MostPopularRequest) (*MostPopularResponse, error) {
var (
err error
res []*nyt.MostPopularResult
)
defer server.MonitorRPCRequest()(ctx, "GetMostPopular", &err)
res, err = s.client.GetMostPopular(r.ResourceType, r.Section, uint(r.TimePeriodDays))
if err != nil {
return nil, err
}
return &MostPopularResponse{res}, nil
}
func (s *RPCService) GetMostPopularJSON(ctx context.Context, r *http.Request) (int, interface{}, error) {
res, err := s.GetMostPopular(
ctx,
&MostPopularRequest{
web.Vars(r)["resourceType"],
web.Vars(r)["section"],
uint32(web.GetUInt64Var(r, "timeframe")),
})
if err != nil {
return http.StatusInternalServerError, nil, err
}
return http.StatusOK, res.Result, nil
}