Created
April 21, 2017 12:13
-
-
Save heltonmarx/6a430eb3b153b9af0c08d2acde869e6d to your computer and use it in GitHub Desktop.
gosep help gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package goseq | |
import ( | |
"bytes" | |
"encoding/json" | |
"fmt" | |
) | |
const ( | |
endpoint = "/api/events/raw" | |
) | |
type Client struct { | |
BaseURL string | |
} | |
func (c *Client) Send(event *SeqLog, apiKey string) error { | |
fullURL := c.BaseURL + endpoint | |
b, err := json.Marshal(event) | |
if err != nil { | |
return err | |
} | |
req, err := http.NewRequest("POST", fullURL, bytes.NewBuffer(b)) | |
if err != nil { | |
return err | |
} | |
if apiKey != "" { | |
req.Header.Set("X-Seq-ApiKey", apiKey) | |
req.Header.Set("Content-Type", "application/json") | |
} | |
client := &http.Client{} | |
resp, err := client.Do(req) | |
if err != nil { | |
return err | |
} | |
defer resp.Body.Close() | |
if resp.StatusCode != http.StatusOk { | |
return fmt.Errorf("returns an invalid status code %v\n", resp.StatusCode) | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment