Skip to content

Instantly share code, notes, and snippets.

@heltonmarx
Created April 21, 2017 12:13
Show Gist options
  • Save heltonmarx/6a430eb3b153b9af0c08d2acde869e6d to your computer and use it in GitHub Desktop.
Save heltonmarx/6a430eb3b153b9af0c08d2acde869e6d to your computer and use it in GitHub Desktop.
gosep help gist
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