Commit 0e4fd1ab authored by Corentin Barreau's avatar Corentin Barreau
Browse files

Fix: endpoints URLs

parent 36794f5a
...@@ -24,7 +24,7 @@ func (c *Client) Discovered(URLs []string, URLType string) (discoveredResponse * ...@@ -24,7 +24,7 @@ func (c *Client) Discovered(URLs []string, URLType string) (discoveredResponse *
} }
// build request // build request
req, err := http.NewRequest("POST", discoveredEndpoint, bytes.NewReader(jsonPayload)) req, err := http.NewRequest("POST", discoveredEndpoint.String(), bytes.NewReader(jsonPayload))
if err != nil { if err != nil {
return discoveredResponse, err return discoveredResponse, err
} }
......
...@@ -11,7 +11,7 @@ func (c *Client) Feed(size int) (feedResponse *FeedResponse, err error) { ...@@ -11,7 +11,7 @@ func (c *Client) Feed(size int) (feedResponse *FeedResponse, err error) {
feedResponse = new(FeedResponse) feedResponse = new(FeedResponse)
// build request // build request
req, err := http.NewRequest("GET", feedEndpoint, nil) req, err := http.NewRequest("GET", feedEndpoint.String(), nil)
if err != nil { if err != nil {
return feedResponse, err return feedResponse, err
} }
......
...@@ -23,7 +23,7 @@ func (c *Client) Finished(URLs []URL, URLType string) (finishedResponse *Finishe ...@@ -23,7 +23,7 @@ func (c *Client) Finished(URLs []URL, URLType string) (finishedResponse *Finishe
} }
// build request // build request
req, err := http.NewRequest("POST", finishedEndpoint, bytes.NewReader(jsonPayload)) req, err := http.NewRequest("POST", finishedEndpoint.String(), bytes.NewReader(jsonPayload))
if err != nil { if err != nil {
return finishedResponse, err return finishedResponse, err
} }
......
...@@ -2,13 +2,14 @@ package gocrawlhq ...@@ -2,13 +2,14 @@ package gocrawlhq
import ( import (
"net/http" "net/http"
"net/url"
"path" "path"
) )
var ( var (
discoveredEndpoint string discoveredEndpoint *url.URL
finishedEndpoint string finishedEndpoint *url.URL
feedEndpoint string feedEndpoint *url.URL
Version = "1.0.0" Version = "1.0.0"
) )
...@@ -22,9 +23,24 @@ func Init(key, secret, project, HQAddress string) (c *Client, err error) { ...@@ -22,9 +23,24 @@ func Init(key, secret, project, HQAddress string) (c *Client, err error) {
c.HTTPClient = http.DefaultClient c.HTTPClient = http.DefaultClient
c.HQAddress = HQAddress c.HQAddress = HQAddress
discoveredEndpoint = path.Join(c.HQAddress + "discovered") discoveredEndpoint, err := url.Parse(c.HQAddress)
finishedEndpoint = path.Join(c.HQAddress + "finished") if err != nil {
feedEndpoint = path.Join(c.HQAddress + "feed") return c, err
}
finishedEndpoint, err := url.Parse(c.HQAddress)
if err != nil {
return c, err
}
feedEndpoint, err := url.Parse(c.HQAddress)
if err != nil {
return c, err
}
discoveredEndpoint.Path = path.Join(discoveredEndpoint.Path, "discovered")
finishedEndpoint.Path = path.Join(finishedEndpoint.Path, "finished")
feedEndpoint.Path = path.Join(feedEndpoint.Path, "feed")
return c, nil return c, nil
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment