Commit 12af3bef authored by Jake LaFountain's avatar Jake LaFountain
Browse files

feat: allow passing in of URL array to allow other variables to be sent through.

Explicitly error out on empty status code to allow clients to better handle.
parent 79084b8c
...@@ -7,15 +7,14 @@ import ( ...@@ -7,15 +7,14 @@ import (
"net/http" "net/http"
) )
func (c *Client) Discovered(URLs []string, URLType string, bypassSeencheck bool) (discoveredResponse *DiscoveredResponse, err error) { func (c *Client) Discovered(URLs []URL, URLType string, bypassSeencheck bool) (discoveredResponse *DiscoveredResponse, err error) {
expectedStatusCode := 201 expectedStatusCode := 201
discoveredResponse = new(DiscoveredResponse) discoveredResponse = new(DiscoveredResponse)
// build payload // build payload
var URLsPayload []URL var URLsPayload []URL
for _, URLString := range URLs {
URLsPayload = append(URLsPayload, URL{Value: URLString}) URLsPayload = append(URLsPayload, URLs...)
}
payload := DiscoveredPayload{ payload := DiscoveredPayload{
Project: c.Project, Project: c.Project,
......
...@@ -2,6 +2,7 @@ package gocrawlhq ...@@ -2,6 +2,7 @@ package gocrawlhq
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"net/http" "net/http"
"strconv" "strconv"
...@@ -9,6 +10,7 @@ import ( ...@@ -9,6 +10,7 @@ import (
func (c *Client) Feed(size int) (feedResponse *FeedResponse, err error) { func (c *Client) Feed(size int) (feedResponse *FeedResponse, err error) {
expectedStatusCode := 200 expectedStatusCode := 200
emptyStatusCode := 204
feedResponse = new(FeedResponse) feedResponse = new(FeedResponse)
// build request // build request
...@@ -32,7 +34,12 @@ func (c *Client) Feed(size int) (feedResponse *FeedResponse, err error) { ...@@ -32,7 +34,12 @@ func (c *Client) Feed(size int) (feedResponse *FeedResponse, err error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
// check response status code // check response status code for 'empty' or 204
if resp.StatusCode == emptyStatusCode {
return feedResponse, errors.New("gocrawlhq: feed is empty")
}
// check response status code for 200
if resp.StatusCode != expectedStatusCode { if resp.StatusCode != expectedStatusCode {
return feedResponse, fmt.Errorf("non-%d status code: %d", expectedStatusCode, resp.StatusCode) return feedResponse, fmt.Errorf("non-%d status code: %d", expectedStatusCode, resp.StatusCode)
} }
......
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