func (s *MixedService) GetMostPopular(r *http.Request) (int, interface{}, error) { resourceType := web.Vars(r)["resourceType"] section := web.Vars(r)["section"] timeframe := web.GetUInt64Var(r, "timeframe") res, err := s.client.GetMostPopular(resourceType, section, uint(timeframe)) if err != nil { return http.StatusInternalServerError, nil, &jsonErr{err.Error()} } return http.StatusOK, 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 }
// GetIP returns the IP address for the given request. func GetIP(r *http.Request) (string, error) { ip, ok := web.Vars(r)["ip"] if ok { return ip, nil } // check real ip header first ip = r.Header.Get("X-Real-IP") if len(ip) > 0 { return ip, nil } // no nginx reverse proxy? // get IP old fashioned way ip, _, err := net.SplitHostPort(r.RemoteAddr) if err != nil { return "", fmt.Errorf("%q is not IP:port", r.RemoteAddr) } userIP := net.ParseIP(ip) if userIP == nil { return "", fmt.Errorf("%q is not IP:port", r.RemoteAddr) } return userIP.String(), nil }
func (s *benchmarkSimpleService) GetSimple(w http.ResponseWriter, r *http.Request) { something := web.Vars(r)["something"] fmt.Fprint(w, something) }
func (s *benchmarkContextService) GetSimple(ctx context.Context, w http.ResponseWriter, r *http.Request) { something := web.Vars(r)["something"] fmt.Fprint(w, something) }
func (s *benchmarkJSONService) GetJSONParam(r *http.Request) (int, interface{}, error) { something := web.Vars(r)["something"] return http.StatusOK, &testJSON{"hi", something}, nil }