mirror of
https://bitbucket.org/skobkin/point-tools-crawler.git
synced 2024-12-05 02:25:53 +00:00
Code style fix.
This commit is contained in:
parent
8502252e8f
commit
a1e1478fb5
|
@ -31,16 +31,16 @@ func (c *PointClient) Login(login, password string) (Token, error) {
|
||||||
data.Set("login", login)
|
data.Set("login", login)
|
||||||
data.Set("password", password)
|
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 {
|
if reqErr != nil {
|
||||||
return token, req_err
|
return token, reqErr
|
||||||
}
|
}
|
||||||
|
|
||||||
json_err := json.Unmarshal(body, &token)
|
jsonErr := json.Unmarshal(body, &token)
|
||||||
|
|
||||||
if json_err != nil {
|
if jsonErr != nil {
|
||||||
log.Fatal(json_err)
|
log.Fatal(jsonErr)
|
||||||
return token, errors.New("JSON deserialization error")
|
return token, errors.New("JSON deserialization error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,16 +65,16 @@ func (c *PointClient) GetRecentAllPostsPage() (Page, error) {
|
||||||
"Authorization": c.token.AuthToken,
|
"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")
|
return page, errors.New("HTTP request error")
|
||||||
}
|
}
|
||||||
|
|
||||||
json_err := json.Unmarshal(body, &page)
|
jsonErr := json.Unmarshal(body, &page)
|
||||||
|
|
||||||
if json_err != nil {
|
if jsonErr != nil {
|
||||||
log.Fatal(json_err)
|
log.Fatal(jsonErr)
|
||||||
return page, errors.New("JSON deserialization error")
|
return page, errors.New("JSON deserialization error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"bitbucket.org/skobkin/point-tools-crawler/point"
|
"bitbucket.org/skobkin/point-tools-crawler/point"
|
||||||
"bitbucket.org/skobkin/point-tools-crawler/point_tools"
|
"bitbucket.org/skobkin/point-tools-crawler/point_tools"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -93,5 +93,3 @@ func main() {
|
||||||
|
|
||||||
fmt.Println("Exiting.")
|
fmt.Println("Exiting.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package point_tools
|
package point_tools
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bitbucket.org/skobkin/point-tools-crawler/point"
|
||||||
"bitbucket.org/skobkin/point-tools-crawler/simple_http"
|
"bitbucket.org/skobkin/point-tools-crawler/simple_http"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"bitbucket.org/skobkin/point-tools-crawler/point"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PointToolsClient struct {
|
type PointToolsClient struct {
|
||||||
|
@ -45,17 +45,17 @@ func (c *PointToolsClient) SendPage(page point.Page) (ReceiveAllPageResponse, er
|
||||||
data.Set("token", "test_token")
|
data.Set("token", "test_token")
|
||||||
data.Add("json", jsonStr)
|
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 {
|
if reqErr != nil {
|
||||||
return response, req_err
|
return response, reqErr
|
||||||
}
|
}
|
||||||
|
|
||||||
json_err := json.Unmarshal(body, &response)
|
jsonErr := json.Unmarshal(body, &response)
|
||||||
|
|
||||||
if json_err != nil {
|
if jsonErr != nil {
|
||||||
return response, json_err
|
return response, jsonErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,11 @@ type Client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) getResponseBody(resp *http.Response) ([]byte, error) {
|
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 {
|
if readErr != nil {
|
||||||
log.Fatal(read_err)
|
log.Fatal(readErr)
|
||||||
return nil, read_err
|
return nil, readErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return body, nil
|
return body, nil
|
||||||
|
@ -30,11 +30,11 @@ func (c *Client) MakeGetRequest(url string, params *url.Values, headers *map[str
|
||||||
url += "?" + params.Encode()
|
url += "?" + params.Encode()
|
||||||
}
|
}
|
||||||
|
|
||||||
req, req_err := http.NewRequest("GET", url, nil)
|
req, reqErr := http.NewRequest("GET", url, nil)
|
||||||
|
|
||||||
if req_err != nil {
|
if reqErr != nil {
|
||||||
log.Fatal(req_err)
|
log.Fatal(reqErr)
|
||||||
return body, req_err
|
return body, reqErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Headers
|
// 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 {
|
if respErr != nil {
|
||||||
log.Fatal(resp_err)
|
log.Fatal(respErr)
|
||||||
return nil, resp_err
|
return nil, respErr
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, read_err := c.getResponseBody(resp)
|
body, readErr := c.getResponseBody(resp)
|
||||||
|
|
||||||
if read_err != nil {
|
if readErr != nil {
|
||||||
return nil, read_err
|
return nil, readErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return body, nil
|
return body, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) MakePostRequest(url string, params url.Values, headers *map[string]string) ([]byte, error) {
|
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 {
|
if reqErr != nil {
|
||||||
log.Fatal(req_err)
|
log.Fatal(reqErr)
|
||||||
return nil, req_err
|
return nil, reqErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adding necessary for POST request header
|
// 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 {
|
if respErr != nil {
|
||||||
log.Fatal(resp_err)
|
log.Fatal(respErr)
|
||||||
return nil, resp_err
|
return nil, respErr
|
||||||
}
|
}
|
||||||
|
|
||||||
body, read_err := c.getResponseBody(resp)
|
body, readErr := c.getResponseBody(resp)
|
||||||
|
|
||||||
if read_err != nil {
|
if readErr != nil {
|
||||||
return nil, read_err
|
return nil, readErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return body, nil
|
return body, nil
|
||||||
|
|
Loading…
Reference in a new issue