Docs

  • Channels Channels
  • Beams Beams
  • Developers
  • Support
  • Blog
  • Sign up
    • Search powered by Algolia
    • Sign in
    • Sign up
    • Channels
    • Beams
    • Getting started
      • Android
        • 1. Configure FCM
        • 2. Integrate SDK
        • 3. Initialize Beams
        • 4. Publish Notifications
      • iOS
        • 1. Configure APNS
        • 2. Integrate SDK
        • 3. Publish Notifications
      • Web
        • 1. SDK integration
        • 2. Safari configuration
      • Flutter
        • 1. Configure FCM and APNS
        • 2. Integrate SDK
        • 4. Publish Notifications
    • Concepts
      • Subscribers
      • Device interests
      • Authenticated users
      • Insights
      • Webhooks
    • Guides
      • Handle incoming notifications
        • Android
        • iOS
        • Web
        • Flutter
      • Publishing to multiple devices
      • Publish to specific user
        • Android
        • iOS
        • Web
        • Flutter
      • Web push guides
        • Using an existing service worker
        • Web notification permissions in Firefox
        • Handling Safari certificate expiration
    • Reference
      • Client SDKs
        • Android
        • iOS
        • Web
      • All Libraries
      • Server SDKs
        • Go
        • PHP
        • Node.js
        • Python
        • Java/Kotlin
        • Ruby
        • Swift
      • API
        • Publish API
        • Customer API
        • Device API
        • Reporting API
        • Webhooks
      • Platform Publish Formats
    • Pusher lab

    Go Server SDK

    ∞ Installation

    You can install this SDK by doing:

    go get github.com/pusher/push-notifications-go

    ∞ Reference

    ∞ .New

    Constructs a new Beams client instance using your instance id and secret key (you can get these from the dashboard)

    ∞ Arguments

    ∞ instanceIdString Required

    The unique identifier for your Push notifications instance. This can be found in the dashboard under “Credentials”.

    ∞ secretKeyString Required

    The secret key your server will use to access your Beams instance. This can be found in the dashboard under “Credentials”.

    ∞ optionsOption | vararg Optional

    Variadic list of options for configuring the SDK

    ∞ Returns

    ∞ clientPushNotifications

    Beams API client implementing the PushNotifications interface.

    ∞ errError

    Error value if something went wrong, nil otherwise.

    ∞ Example

    const (
    instanceId = "YOUR_INSTANCE_ID_HERE"
    secretKey = "YOUR_SECRET_KEY_HERE"
    )

    beamsClient, err := pushnotifications.New(instanceId, secretKey)
    if err != nil {
    fmt.Println("Could not create Beams Client:", err.Error())
    }

    ∞ .PublishToInterests

    Sends broadcast notifications to groups of subscribed devices using Device Interests

    ∞ Arguments

    ∞ interests[]string | Min length=1, Max length=100 Required

    List of interests to send the push notification to, ranging from 1 to 100 per publish request. See Device Interests

    ∞ publishBodymap[string]interface{}

    A map containing the publish request body. See publish API reference

    ∞ Returns

    ∞ publishIDstring

    Unique identifier for the publish request.

    ∞ errerror

    Error value if something went wrong, nil otherwise.

    ∞ Example

    publishRequest := map[string]interface{}{
    "apns": map[string]interface{}{
    "aps": map[string]interface{}{
    "alert": map[string]interface{}{
    "title": "Hello",
    "body": "Hello, world",
    },
    },
    },
    "fcm": map[string]interface{}{
    "notification": map[string]interface{}{
    "title": "Hello",
    "body": "Hello, world",
    },
    },
    "web": map[string]interface{}{
    "notification": map[string]interface{}{
    "title": "Hello",
    "body": "Hello, world",
    },
    },
    }

    pubId, err := beamsClient.PublishToInterests([]string{"hello"}, publishRequest)
    if err != nil {
    fmt.Println(err)
    } else {
    fmt.Println("Publish Id:", pubId)
    }

    ∞ .PublishToUsers

    Securely send notifications to individual users of your application using Authenticated Users

    ∞ Arguments

    ∞ userIds[]string | Min length=1, Max length=1000 Required

    List of ids of users to send the push notification to, ranging from 1 to 1000 per publish request. See Authenticated Users

    ∞ publishBodymap[string]interface{}

    A map containing the publish request body. See publish API reference

    ∞ Returns

    ∞ publishIDstring

    Unique identifier for the publish request.

    ∞ errerror

    Error value if something went wrong, nil otherwise.

    ∞ Example

    publishRequest := map[string]interface{}{
    "apns": map[string]interface{}{
    "aps": map[string]interface{}{
    "alert": map[string]interface{}{
    "title": "Hello",
    "body": "Hello, world",
    },
    },
    },
    "fcm": map[string]interface{}{
    "notification": map[string]interface{}{
    "title": "Hello",
    "body": "Hello, world",
    },
    },
    "web": map[string]interface{}{
    "notification": map[string]interface{}{
    "title": "Hello",
    "body": "Hello, world",
    },
    },
    }

    pubId, err := beamsClient.PublishToUsers([]string{"user-001", "user-002"}, publishRequest)
    if err != nil {
    fmt.Println(err)
    } else {
    fmt.Println("Publish Id:", pubId)
    }

    ∞ .GenerateToken

    Generate a Beams auth token to allow a user to associate their device with their user id. The token is valid for 24 hours.

    ∞ Arguments

    ∞ userIDstring Required

    ID of the user you would like to generate a Beams auth token for

    ∞ Returns

    ∞ beamsTokenstring

    Beams Token for the given user

    ∞ errerror

    Error value if something went wrong, nil otherwise.

    ∞ Example

    userID := "user-001"
    beamsToken, err := beamsClient.GenerateToken(userID)
    if err != nil {
    fmt.Println("Could not generate Beams token:", err.Error())
    }

    ∞ .DeleteUser

    Remove the given user (and all of their devices) from Beams. This user will no longer receive any notifications and all state stored about their devices will be deleted.

    ∞ Arguments

    ∞ userIDstring Required

    ID of the user you would like to delete from Beams.

    ∞ Returns

    ∞ errerror

    Error value if something went wrong, nil otherwise.

    ∞ Example

    userID := "user-001"
    err := beamsClient.DeleteUser(userID)
    if err != nil {
    fmt.Println("Could not delete user:", err.Error())
    }

    Contents

    • Installation
    • Reference
      • .New
      • .PublishToInterests
      • .PublishToUsers
      • .GenerateToken
      • .DeleteUser

    Spotted something that isn’t quite right? Create an issue on GitHub.

    Copyright © 2024 Pusher Ltd. All rights reserved.

    • Support,
    • Status
    • Follow Pusher on Twitter Twitter
    • Subscribe to Pusher’s channel on YouTube
    • Follow Pusher on LinkedIn
    • Follow Pusher on Github GitHub
    • Follow Pusher on Twitch Twitch
    • Follow Pusher on Discord Discord
    OSZAR »