Add go sdk

This commit is contained in:
Oliver
2026-01-06 14:55:21 +01:00
parent 32bcd6db9e
commit e018bedca3
21 changed files with 1090 additions and 0 deletions

46
client/events.go Normal file
View File

@@ -0,0 +1,46 @@
package client
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"time"
)
func (c *Client) SendEvent(evt *Event) error {
dto := createEventDTO{
ProjectID: c.projectID,
Name: evt.Name,
Timestamp: time.Now(),
Properties: evt.Properties,
WriteKey: c.writeKey,
}
body, err := json.Marshal(dto)
if err != nil {
return fmt.Errorf("could not marshal event: %w", err)
}
req, err := http.NewRequest(http.MethodPost, c.baseURL+"/collector/api/v1/events", bytes.NewBuffer(body))
if err != nil {
return fmt.Errorf("could not create request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
if c.authToken != "" {
req.Header.Set("Authorization", "Bearer "+c.authToken)
}
resp, err := c.client.Do(req)
if err != nil {
return fmt.Errorf("could not send request: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return ErrUnexpectedStatusCode
}
return nil
}