Go SDK
github.com/emitwave/go-sdk — a server-side Go SDK for publishing signed events.
Server SDK· 4 min read
Install
bash
go get github.com/emitwave/go-sdk@latest
Requires Go 1.26+, an application ID, and an active server credential. Keep the secret on the server.
Key and Secret are a server credential, not the browser public key. The SDK hashes the JSON body and HMAC-signs the method, path, canonical query, and body hash before the gateway validates it.Publish an event
Trigger publishes to all external channel types. When data is nil, the SDK sends an empty JSON object.
main.go
package main import ( "context" "log" "os" "time" emitwave "github.com/emitwave/go-sdk" ) func main() { client, err := emitwave.New(emitwave.Config{ // GatewayURL defaults to https://api.emitwave.com AppID: os.Getenv("EMITWAVE_APP_ID"), Key: os.Getenv("EMITWAVE_KEY"), Secret: os.Getenv("EMITWAVE_SECRET"), }) if err != nil { log.Fatal(err) } ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() err = client.Trigger(ctx, "orders", "order.created", map[string]any{ "id": "ord_123", "total": 4900, }) if err != nil { log.Fatal(err) } }
Custom HTTP client
client.go
client, err := emitwave.New(emitwave.Config{ GatewayURL: "https://api.emitwave.com", AppID: appID, Key: key, Secret: secret, HTTPClient: &http.Client{Timeout: 3 * time.Second}, })
Error handling
The SDK returns *EmitwaveError for non-2xx responses and wrapped Go errors for configuration, serialization, request construction, or transport failures.
errors.go
var gatewayError *emitwave.EmitwaveError if err := client.Trigger(ctx, channel, event, data); err != nil { if errors.As(err, &gatewayError) { log.Printf("rejected: HTTP %d: %s", gatewayError.Status, gatewayError.Body) } else { log.Printf("transport error: %v", err) } }
The Go SDK publishes the supplied data unchanged. It does not build the ciphertext envelope for private-encrypted channels — see Encryption.