Server SDK · Go services

Go SDK

Go 1.22+. Standard library only, with context cancellation and concurrent client use.

Install from GitHub

The SDK source is public on the main branch. These instructions use Git or a locally built package; package registry releases are a separate step.

Installation
go get github.com/pubbio/sdk-go@main

Go records the resolved commit as a pseudo-version in your application's go.mod.

Publish an event

Set PUBB_APP_ID, PUBB_APP_KEY and PUBB_APP_SECRET in your server environment, then publish after checking the caller's permissions.

main.go
package main

import (
    "context"
    "fmt"
    "log"
    "os"
    pubb "github.com/pubbio/sdk-go"
)

func main() {
    client, err := pubb.NewClient(pubb.Config{
        AppID: os.Getenv("PUBB_APP_ID"), AppKey: os.Getenv("PUBB_APP_KEY"),
        AppSecret: os.Getenv("PUBB_APP_SECRET"),
    })
    if err != nil { log.Fatal(err) }
    result, err := client.Trigger(context.Background(), []string{"notifications"},
        "message.sent", map[string]string{"message": "Hello from Pubb!"}, nil)
    if err != nil { log.Fatal(err) }
    fmt.Println(result.PublicationID)
}

Pass TriggerOptions for SocketID and IdempotencyKey. Requests honor context cancellation and the configured HTTP client timeout. APIError exposes StatusCode and RetryAfter. A custom HTTP client is copied, keeps its transport ownership, and has redirects disabled.

HTTP 202 confirms acceptance for processing, not delivery. The response includes publicationId and duplicate. SDKs do not automatically retry publications; reuse an idempotency key when retrying the same event. The API accepts 1–100 channels and up to 10 KiB of UTF-8 JSON data.

Private and presence channels

Use AuthorizeChannel(socketID, channel) or AuthorizePresenceChannel(socketID, channel, verifiedUserID, userInfo) after checking access. Serialize the returned Authorization value as JSON and forward ChannelData unchanged.

Your backend receives socket_id and channel_name, checks the authenticated user’s access, and returns auth plus channel_data for presence. Derive the presence user ID from the session and forward the signed channel_data unchanged.

Keep the app secret on your trusted server. Public channels must not carry personal or restricted data. Read the channel access reference for the protocol.

Verify your integration

  1. Subscribe to notifications in your app or the dashboard’s Live console.
  2. Publish message.sent to the same application and channel from your backend.
  3. Check the event payload, connection cleanup and recovery after a disconnect. Test denied access as well as successful private subscriptions.

The repositories include automated tests and examples. Verify end-to-end delivery with your own application before sending production traffic. Refetch durable state after reconnecting; missed events are not replayed.

Legacy pusher:* and pusher_internal:* control names are retained where required by the protocol. Their presence alone does not imply drop-in compatibility with every Pusher client or server.