Lazers/Documentation/Go SDK Guide
SDKs

Go SDK Guide

Pure standard-library Go SDK (Go 1.22+) featuring concurrent safe queues, panic recovery, and net/http, Gin, Fiber, and Echo middleware.

The Lazers Go SDK (`github.com/Emmydapson/lazers/packages/go-sdk`) requires Go 1.22+ and imports only standard library packages. A background goroutine manages batching and rate limiting.

Installation ```bash go get github.com/Emmydapson/lazers/packages/go-sdk@v0.1.0 ```

Integration Code Examples

net/http with Panic Recovery
package main

import (
    "context"
    "fmt"
    "net/http"
    "os"
    "os/signal"
    "syscall"
    "time"

    lazers "github.com/Emmydapson/lazers/packages/go-sdk"
)

func main() {
    client, err := lazers.NewClient(lazers.Config{
        APIKey:      os.Getenv("LAZERS_API_KEY"),
        Endpoint:    "https://api.lazers.app",
        ProjectID:   os.Getenv("LAZERS_PROJECT_ID"),
        Environment: "production",
        ServiceName: "payment-gateway",
        Release:     os.Getenv("GIT_COMMIT"),
    })
    if err != nil {
        panic(err)
    }
    defer client.Close(context.Background())

    mux := http.NewServeMux()
    mux.HandleFunc("/charge", func(w http.ResponseWriter, r *http.Request) {
        defer func() {
            if rec := recover(); rec != nil {
                err := fmt.Errorf("panic in charge handler: %v", rec)
                client.CaptureError(err, lazers.CaptureContext{
                    CorrelationID: r.Header.Get("X-Request-ID"),
                    Actor: map[string]any{"type": "user", "id": "usr_942"},
                })
                http.Error(w, "Internal Server Error", 500)
            }
        }()
        // Business logic...
    })

    server := &http.Server{Addr: ":8080", Handler: mux}
    go server.ListenAndServe()

    // Graceful shutdown
    stop := make(chan os.Signal, 1)
    signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT)
    <-stop

    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    defer cancel()
    _ = client.Close(ctx)
}

Ready to test with your service?

Create a project, generate an API key or Client DSN, and send a signal in 2 minutes.