Skip to content

Commit

Permalink
server: rename influxdb.Results type to influxdb.Response (issue: #2050)
Browse files Browse the repository at this point in the history
Rename influxdb.Results to influxdb.Response as it already has Results
property itself. Renaming it to Response makes code look much less
ugly.
  • Loading branch information
peekeri committed Apr 4, 2015
1 parent a56ea6f commit 7046914
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions client/influxdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestClient_Ping(t *testing.T) {

func TestClient_Query(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var data influxdb.Results
var data influxdb.Response
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(data)
}))
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestClient_BasicAuth(t *testing.T) {

func TestClient_Write(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var data influxdb.Results
var data influxdb.Response
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(data)
}))
Expand All @@ -124,7 +124,7 @@ func TestClient_UserAgent(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
receivedUserAgent = r.UserAgent()

var data influxdb.Results
var data influxdb.Response
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(data)
}))
Expand Down
10 changes: 5 additions & 5 deletions httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (h *Handler) serveQuery(w http.ResponseWriter, r *http.Request, user *influ
}

// if we're not chunking, this will be the in memory buffer for all results before sending to client
res := influxdb.Results{Results: make([]*influxdb.Result, 0)}
res := influxdb.Response{Results: make([]*influxdb.Result, 0)}
statusWritten := false

// pull all results from the channel
Expand Down Expand Up @@ -320,7 +320,7 @@ func (h *Handler) showMeasurements(db string, user *influxdb.User) ([]string, er
if err != nil {
return measurements, err
}
results := influxdb.Results{}
results := influxdb.Response{}

for r := range c {
results.Results = append(results.Results, r)
Expand Down Expand Up @@ -691,12 +691,12 @@ func httpError(w http.ResponseWriter, error string, pretty bool, code int) {
w.Header().Add("content-type", "application/json")
w.WriteHeader(code)

results := influxdb.Results{Err: errors.New(error)}
response := influxdb.Response{Err: errors.New(error)}
var b []byte
if pretty {
b, _ = json.MarshalIndent(results, "", " ")
b, _ = json.MarshalIndent(response, "", " ")
} else {
b, _ = json.Marshal(results)
b, _ = json.Marshal(response)
}
w.Write(b)
}
Expand Down
24 changes: 12 additions & 12 deletions httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ func TestHandler_serveWriteSeriesNonZeroTime(t *testing.T) {
t.Errorf("unexpected status: %d", status)
}

r := &influxdb.Results{}
r := &influxdb.Response{}
if err := json.Unmarshal([]byte(body), r); err != nil {
t.Logf("query : %s\n", query)
t.Log(body)
Expand Down Expand Up @@ -1401,7 +1401,7 @@ func TestHandler_serveWriteSeriesZeroTime(t *testing.T) {
t.Errorf("unexpected status: %d", status)
}

r := &influxdb.Results{}
r := &influxdb.Response{}
if err := json.Unmarshal([]byte(body), r); err != nil {
t.Logf("query : %s\n", query)
t.Log(body)
Expand Down Expand Up @@ -1489,7 +1489,7 @@ func TestHandler_serveWriteSeriesBatch(t *testing.T) {
t.Errorf("unexpected status: %d", status)
}

r := &influxdb.Results{}
r := &influxdb.Response{}
if err := json.Unmarshal([]byte(body), r); err != nil {
t.Logf("query : %s\n", query)
t.Log(body)
Expand Down Expand Up @@ -1531,7 +1531,7 @@ func TestHandler_serveWriteSeriesFieldTypeConflict(t *testing.T) {
t.Errorf("unexpected status: %d", status)
}

r := &influxdb.Results{}
r := &influxdb.Response{}
if err := json.Unmarshal([]byte(body), r); err != nil {
t.Log(body)
t.Error(err)
Expand Down Expand Up @@ -1646,25 +1646,25 @@ func TestHandler_ChunkedResponses(t *testing.T) {
if err != nil {
t.Fatalf("error reading response: %s", err.Error())
}
results := &influxdb.Results{}
err = json.Unmarshal(chunk[0:n], results)
response := &influxdb.Response{}
err = json.Unmarshal(chunk[0:n], response)
if err != nil {
t.Fatalf("error unmarshaling resultsz: %s", err.Error())
}
if len(results.Results) != 1 {
t.Fatalf("didn't get 1 result: %s\n", mustMarshalJSON(results))
if len(response.Results) != 1 {
t.Fatalf("didn't get 1 result: %s\n", mustMarshalJSON(response))
}
if len(results.Results[0].Series) != 1 {
t.Fatalf("didn't get 1 series: %s\n", mustMarshalJSON(results))
if len(response.Results[0].Series) != 1 {
t.Fatalf("didn't get 1 series: %s\n", mustMarshalJSON(response))
}
var vals [][]interface{}
if i == 0 {
vals = [][]interface{}{{"2009-11-10T23:00:00Z", 100}}
} else {
vals = [][]interface{}{{"2009-11-10T23:30:00Z", 25}}
}
if mustMarshalJSON(vals) != mustMarshalJSON(results.Results[0].Series[0].Values) {
t.Fatalf("values weren't what was expected:\n exp: %s\n got: %s", mustMarshalJSON(vals), mustMarshalJSON(results.Results[0].Series[0].Values))
if mustMarshalJSON(vals) != mustMarshalJSON(response.Results[0].Series[0].Values) {
t.Fatalf("values weren't what was expected:\n exp: %s\n got: %s", mustMarshalJSON(vals), mustMarshalJSON(response.Results[0].Series[0].Values))
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3318,14 +3318,14 @@ func (r *Result) UnmarshalJSON(b []byte) error {
return nil
}

// Results represents a list of statement results.
type Results struct {
// Response represents a list of statement results.
type Response struct {
Results []*Result
Err error
}

// MarshalJSON encodes a Results struct into JSON.
func (r Results) MarshalJSON() ([]byte, error) {
// MarshalJSON encodes a Response struct into JSON.
func (r Response) MarshalJSON() ([]byte, error) {
// Define a struct that outputs "error" as a string.
var o struct {
Results []*Result `json:"results,omitempty"`
Expand All @@ -3341,8 +3341,8 @@ func (r Results) MarshalJSON() ([]byte, error) {
return json.Marshal(&o)
}

// UnmarshalJSON decodes the data into the Results struct
func (r *Results) UnmarshalJSON(b []byte) error {
// UnmarshalJSON decodes the data into the Response struct
func (r *Response) UnmarshalJSON(b []byte) error {
var o struct {
Results []*Result `json:"results,omitempty"`
Err string `json:"error,omitempty"`
Expand All @@ -3361,7 +3361,7 @@ func (r *Results) UnmarshalJSON(b []byte) error {

// Error returns the first error from any statement.
// Returns nil if no errors occurred on any statements.
func (r *Results) Error() error {
func (r *Response) Error() error {
if r.Err != nil {
return r.Err
}
Expand Down
6 changes: 3 additions & 3 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1945,12 +1945,12 @@ func (s *Server) MustWriteSeries(database, retentionPolicy string, points []infl
return index
}

func (s *Server) executeQuery(q *influxql.Query, db string, user *influxdb.User) influxdb.Results {
func (s *Server) executeQuery(q *influxql.Query, db string, user *influxdb.User) influxdb.Response {
results, err := s.ExecuteQuery(q, db, user, 10000)
if err != nil {
return influxdb.Results{Err: err}
return influxdb.Response{Err: err}
}
res := influxdb.Results{}
res := influxdb.Response{}
for r := range results {
l := len(res.Results)
if l == 0 {
Expand Down

0 comments on commit 7046914

Please sign in to comment.