Go client
Send logs from Go using the same ingestion API. No SDK required—use the standard library. The example below matches the runnable code in examples/go/ in the repo.
Quick start
- Install: Nothing. Use
net/httpandencoding/json. - Endpoint:
POST /v1/logs(e.g.http://localhost:3000/v1/logsor your API URL). - Headers:
Authorization: Bearer <api_key>,Content-Type: application/json. - Body:
{"events":[{ "message":"...", "level":"info", "timestamp":"...", "metadata":{} }]}— max 100 events per request.
Environment variables
Set LOGGER_API_KEY (from dashboard). For hosted Logship set LOGGER_API_URL to the ingestion URL from the dashboard; for local dev use http://localhost:3000. (The Node SDK has this URL built in, so Node users only set the key.)
LOGGER_API_KEY=lb_sb_xxxxLOGGER_API_URL=http://localhost:3000Example (from examples/go)
Minimal runnable example from examples/go/main.go:
package main
import ( "bytes" "encoding/json" "fmt" "net/http" "os" "time")
type LogEvent struct { Level string `json:"level,omitempty"` Message string `json:"message"` Timestamp string `json:"timestamp,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty"` Env string `json:"env,omitempty"` Source string `json:"source,omitempty"`}
type LogsRequest struct { Events []LogEvent `json:"events"`}
func main() { apiKey := os.Getenv("LOGGER_API_KEY") if apiKey == "" { fmt.Fprintln(os.Stderr, "LOGGER_API_KEY is required") os.Exit(1) } baseURL := os.Getenv("LOGGER_API_URL") if baseURL == "" { baseURL = "http://localhost:3000" } url := baseURL + "/v1/logs"
events := []LogEvent{{ Level: "info", Message: "Hello from Go", Timestamp: time.Now().UTC().Format(time.RFC3339), Metadata: map[string]interface{}{"lang": "go"}, Env: os.Getenv("APP_ENV"), Source: "server", }} body, err := json.Marshal(LogsRequest{Events: events}) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) }
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body)) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } req.Header.Set("Authorization", "Bearer "+apiKey) req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } defer resp.Body.Close()
switch resp.StatusCode { case http.StatusOK, http.StatusAccepted: fmt.Println("Log sent successfully.") default: fmt.Fprintf(os.Stderr, "Logger API returned %d\n", resp.StatusCode) os.Exit(1) }}Run: go run main.go (from examples/go/). Check the dashboard Logs for the event.
Full reference
The same ingestion API (POST /v1/logs) is used from Go. Request shape, responses (202, 400, 401, 429, 503), and this minimal runnable example are in the repo:
- documentation/LOGGER_GO_CLIENT.md – Full request/response and Go client notes.
- examples/go/ – Runnable Go example (main.go above).
For endpoint details, headers, rate limits, and body limits, see the API reference.