package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
"time"
)
type LogEntry struct {
ProjectID string `json:"projectId"`
Level string `json:"level"`
Message string `json:"message"`
Source string `json:"source,omitempty"`
Timestamp string `json:"timestamp"`
Tags []string `json:"tags,omitempty"`
Meta map[string]any `json:"meta,omitempty"`
}
func ingest(entries []LogEntry) error {
body, err := json.Marshal(entries)
if err != nil {
return err
}
req, _ := http.NewRequest("POST", "https://api.streamlogia.com/v1/ingest", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("LOGINGESTOR_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
return fmt.Errorf("ingest failed with status %d", resp.StatusCode)
}
return nil
}
func main() {
ingest([]LogEntry{{
ProjectID: os.Getenv("LOGINGESTOR_PROJECT_ID"),
Level: "INFO",
Message: "Hello, Streamlogia!",
Source: "my-service",
Timestamp: time.Now().UTC().Format(time.RFC3339),
}})
}