Code style fix.

This commit is contained in:
Alexey Skobkin 2016-03-21 23:54:09 +03:00
parent 8502252e8f
commit a1e1478fb5
4 changed files with 48 additions and 50 deletions

View file

@ -31,16 +31,16 @@ func (c *PointClient) Login(login, password string) (Token, error) {
data.Set("login", login)
data.Set("password", password)
body, req_err := c.client.MakePostRequest(c.apiUrl+"login", data, nil)
body, reqErr := c.client.MakePostRequest(c.apiUrl+"login", data, nil)
if req_err != nil {
return token, req_err
if reqErr != nil {
return token, reqErr
}
json_err := json.Unmarshal(body, &token)
jsonErr := json.Unmarshal(body, &token)
if json_err != nil {
log.Fatal(json_err)
if jsonErr != nil {
log.Fatal(jsonErr)
return token, errors.New("JSON deserialization error")
}
@ -65,16 +65,16 @@ func (c *PointClient) GetRecentAllPostsPage() (Page, error) {
"Authorization": c.token.AuthToken,
}
body, req_err := c.client.MakeGetRequest(c.apiUrl+"all", nil, &headers)
body, reqErr := c.client.MakeGetRequest(c.apiUrl+"all", nil, &headers)
if req_err != nil {
if reqErr != nil {
return page, errors.New("HTTP request error")
}
json_err := json.Unmarshal(body, &page)
jsonErr := json.Unmarshal(body, &page)
if json_err != nil {
log.Fatal(json_err)
if jsonErr != nil {
log.Fatal(jsonErr)
return page, errors.New("JSON deserialization error")
}

View file

@ -1,13 +1,13 @@
package main
import (
"flag"
"fmt"
"bitbucket.org/skobkin/point-tools-crawler/point"
"bitbucket.org/skobkin/point-tools-crawler/point_tools"
"flag"
"fmt"
"log"
"time"
"strconv"
"time"
)
func main() {
@ -93,5 +93,3 @@ func main() {
fmt.Println("Exiting.")
}

View file

@ -1,12 +1,12 @@
package point_tools
import (
"bitbucket.org/skobkin/point-tools-crawler/point"
"bitbucket.org/skobkin/point-tools-crawler/simple_http"
"encoding/json"
"log"
"net/http"
"net/url"
"bitbucket.org/skobkin/point-tools-crawler/point"
)
type PointToolsClient struct {
@ -45,17 +45,17 @@ func (c *PointToolsClient) SendPage(page point.Page) (ReceiveAllPageResponse, er
data.Set("token", "test_token")
data.Add("json", jsonStr)
body, req_err := c.client.MakePostRequest(c.apiUrl+"all/page", data, nil)
body, reqErr := c.client.MakePostRequest(c.apiUrl+"all/page", data, nil)
if req_err != nil {
return response, req_err
if reqErr != nil {
return response, reqErr
}
json_err := json.Unmarshal(body, &response)
jsonErr := json.Unmarshal(body, &response)
if json_err != nil {
return response, json_err
if jsonErr != nil {
return response, jsonErr
}
return response, nil
}
}

View file

@ -13,11 +13,11 @@ type Client struct {
}
func (c *Client) getResponseBody(resp *http.Response) ([]byte, error) {
body, read_err := ioutil.ReadAll(resp.Body)
body, readErr := ioutil.ReadAll(resp.Body)
if read_err != nil {
log.Fatal(read_err)
return nil, read_err
if readErr != nil {
log.Fatal(readErr)
return nil, readErr
}
return body, nil
@ -30,11 +30,11 @@ func (c *Client) MakeGetRequest(url string, params *url.Values, headers *map[str
url += "?" + params.Encode()
}
req, req_err := http.NewRequest("GET", url, nil)
req, reqErr := http.NewRequest("GET", url, nil)
if req_err != nil {
log.Fatal(req_err)
return body, req_err
if reqErr != nil {
log.Fatal(reqErr)
return body, reqErr
}
// Headers
@ -44,30 +44,30 @@ func (c *Client) MakeGetRequest(url string, params *url.Values, headers *map[str
}
}
resp, resp_err := c.HttpClient.Do(req)
resp, respErr := c.HttpClient.Do(req)
if resp_err != nil {
log.Fatal(resp_err)
return nil, resp_err
if respErr != nil {
log.Fatal(respErr)
return nil, respErr
}
defer resp.Body.Close()
body, read_err := c.getResponseBody(resp)
body, readErr := c.getResponseBody(resp)
if read_err != nil {
return nil, read_err
if readErr != nil {
return nil, readErr
}
return body, nil
}
func (c *Client) MakePostRequest(url string, params url.Values, headers *map[string]string) ([]byte, error) {
req, req_err := http.NewRequest("POST", url, strings.NewReader(params.Encode()))
req, reqErr := http.NewRequest("POST", url, strings.NewReader(params.Encode()))
if req_err != nil {
log.Fatal(req_err)
return nil, req_err
if reqErr != nil {
log.Fatal(reqErr)
return nil, reqErr
}
// Adding necessary for POST request header
@ -80,17 +80,17 @@ func (c *Client) MakePostRequest(url string, params url.Values, headers *map[str
}
}
resp, resp_err := c.HttpClient.Do(req)
resp, respErr := c.HttpClient.Do(req)
if resp_err != nil {
log.Fatal(resp_err)
return nil, resp_err
if respErr != nil {
log.Fatal(respErr)
return nil, respErr
}
body, read_err := c.getResponseBody(resp)
body, readErr := c.getResponseBody(resp)
if read_err != nil {
return nil, read_err
if readErr != nil {
return nil, readErr
}
return body, nil