---
source_url: https://www.pubnub.com/docs/sdks/go/api-reference/channel-groups
title: Channel Groups API for Go SDK
updated_at: 2026-06-19T11:37:23.436Z
sdk_name: PubNub Go SDK
sdk_version: v9.0.1
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Channel Groups API for Go SDK

PubNub Go SDK, use the latest version: v9.0.1

Install:

```bash
go get github.com/pubnub/go/v9@v9.0.1
```

[Channel groups](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups) allow PubNub developers to bundle thousands of [channels](https://www.pubnub.com/docs/general/channels/overview) into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.

:::note Channel group operations
You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.
:::

## Add channels to a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the PubNub [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function adds channels to a channel group.

### Method(s)

Use the following method in the Go SDK:

:::note Maximum number of channels
You can add up to 200 channels to a channel group per API call.
:::

```go
pn.AddChannelToChannelGroup().
    Channels([]string).
    ChannelGroup(string).
    QueryParam(queryParam).
    Execute()
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| Channels | []string | Yes |  | The channels to add to the channel group. |
| ChannelGroup | string | Yes |  | The channel group to add the channels to. |
| QueryParam | map[string]string | Optional |  | QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API. |

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

#### Add channels

```go
// Replace with your package name (usually "main")
package pubnub_samples_test

import (
	"fmt"

	pubnub "github.com/pubnub/go/v9"
)

// Example_addChannelsToGroup demonstrates adding channels to a channel group
func Example_addChannelsToGroup() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo" // Replace with your subscribe key
	config.PublishKey = "demo"   // Replace with your publish key

	// snippet.hide
	config = setPubnubExampleConfigData(config)
	// snippet.show

	pn := pubnub.NewPubNub(config)

	// snippet.hide
	defer pn.DeleteChannelGroup().ChannelGroup("my-channel-group").Execute()
	// snippet.show

	// Add channels to a channel group
	// This allows you to subscribe to multiple channels at once using the group name
	_, status, err := pn.AddChannelToChannelGroup().
		Channels([]string{"channel-1", "channel-2", "channel-3"}). // Channels to add
		ChannelGroup("my-channel-group").                          // Channel group name
		Execute()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	if status.StatusCode == 200 {
		fmt.Println("Channels added to group successfully")
	}

	// Output:
	// Channels added to group successfully
}
```

### Response

```go
{
    "service" : "channel-registry",
    "status"  : 200,
    "error"   : false,
    "message" : "OK"
}
```

## List channels in a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function lists all channels in a channel group.

### Method(s)

Use the following method in the Go SDK:

```go
pn.ListChannelsInChannelGroup().
    ChannelGroup(string).
    QueryParam(queryParam).
    Execute()
```

| Parameter | Description |
| --- | --- |
| `ChannelGroup` *Type: string | The channel group for which to list channels. |
| `QueryParam`Type: map[string]string | QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API. |

### Sample code

#### List channels

```go
// Replace with your package name (usually "main")
package pubnub_samples_test

import (
	"fmt"

	pubnub "github.com/pubnub/go/v9"
)

// Example_listChannelsInGroup demonstrates listing all channels in a channel group
func Example_listChannelsInGroup() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo"
	config.PublishKey = "demo"

	// snippet.hide
	config = setPubnubExampleConfigData(config)
	// snippet.show

	pn := pubnub.NewPubNub(config)

	// snippet.hide
	defer pn.DeleteChannelGroup().ChannelGroup("my-channel-group").Execute()
	// snippet.show

	// First, add some channels to the group
	pn.AddChannelToChannelGroup().
		Channels([]string{"channel-1", "channel-2"}).
		ChannelGroup("my-channel-group").
		Execute()

	// List all channels in the channel group
	response, status, err := pn.ListChannelsInChannelGroup().
		ChannelGroup("my-channel-group").
		Execute()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	if status.StatusCode == 200 {
		fmt.Printf("Channels in group: %v\n", response.Channels)
	}

}
```

### Response

| Method | Description |
| --- | --- |
| `Channels`Type: []string | Yes |
| `Group`Type: string | Yes |

## Remove channels from a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function removes channels from a channel group.

### Method(s)

Use the following method in the Go SDK:

```go
pn.RemoveChannelFromChannelGroup().
    ChannelGroup(string).
    Channels([]string).
    QueryParam(queryParam).
    Execute()
```

| Parameter | Description |
| --- | --- |
| `ChannelGroup` *Type: string | The channel group from which to remove the channels. |
| `Channels` *Type: []string | The channels to remove from the channel group. |
| `QueryParam`Type: map[string]string | QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API. |

### Sample code

#### Remove channels

```go
// Replace with your package name (usually "main")
package pubnub_samples_test

import (
	"fmt"

	pubnub "github.com/pubnub/go/v9"
)

// Example_removeChannelsFromGroup demonstrates removing channels from a channel group
func Example_removeChannelsFromGroup() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo"
	config.PublishKey = "demo"

	// snippet.hide
	config = setPubnubExampleConfigData(config)
	// snippet.show

	pn := pubnub.NewPubNub(config)

	// snippet.hide
	defer pn.DeleteChannelGroup().ChannelGroup("my-channel-group").Execute()
	// snippet.show

	// First, add channels to the group
	pn.AddChannelToChannelGroup().
		Channels([]string{"channel-1", "channel-2", "channel-3"}).
		ChannelGroup("my-channel-group").
		Execute()

	// Remove specific channels from the channel group
	_, status, err := pn.RemoveChannelFromChannelGroup().
		Channels([]string{"channel-1"}). // Channels to remove
		ChannelGroup("my-channel-group").
		Execute()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	if status.StatusCode == 200 {
		fmt.Println("Channels removed from group successfully")
	}

	// Output:
	// Channels removed from group successfully
}
```

### Response

```go
{
    Error:<nil>
    Category:Unknown
    Operation:Remove Channel From Channel Group
    StatusCode:200
    TLSEnabled:true
    UUID:d9713e5a-6bcb-439a-942e-5ba064f2e5dd
    AuthKey:
    Origin:ps.pndsn.com
    OriginalResponse: {
        "status": 200,
        "message": "OK",
        "service": "channel-registry",
        "error": false
    }
    AffectedChannels:[]
    AffectedChannelGroups:[]
}
```

## Delete a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function deletes a channel group.

### Method(s)

Use the following method in the Go SDK:

```go
pn.DeleteChannelGroup().
    ChannelGroup(string).
    QueryParam(queryParam).
    Execute()
```

| Parameter | Description |
| --- | --- |
| `ChannelGroup` *Type: string | The channel group to delete. |
| `QueryParam`Type: map[string]string | QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API. |

### Sample code

#### Delete channel group

```go
// Replace with your package name (usually "main")
package pubnub_samples_test

import (
	"fmt"

	pubnub "github.com/pubnub/go/v9"
)

// Example_deleteChannelGroup demonstrates deleting a channel group
func Example_deleteChannelGroup() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo"
	config.PublishKey = "demo"

	// snippet.hide
	config = setPubnubExampleConfigData(config)
	// snippet.show

	pn := pubnub.NewPubNub(config)

	// First, create a channel group with some channels
	pn.AddChannelToChannelGroup().
		Channels([]string{"channel-1", "channel-2"}).
		ChannelGroup("temp-group").
		Execute()

	// Delete the entire channel group
	// This removes the group and all its channel associations
	response, status, err := pn.DeleteChannelGroup().
		ChannelGroup("temp-group").
		Execute()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	if status.StatusCode == 200 {
		fmt.Println("Channel group deleted successfully")
	}

	_ = response

	// Output:
	// Channel group deleted successfully
}
```

### Response

```go
{
    Error:<nil>
    Category:Unknown
    Operation:Remove Channel Group
    StatusCode:200
    TLSEnabled:true
    UUID:650089a0-922c-4de6-b422-7a38a964bf45
    AuthKey:
    Origin:ps.pndsn.com
    OriginalResponse: {
        "status": 200,
        "message": "OK",
        "service": "channel-registry",
        "error": false
    }
    AffectedChannels:[]
    AffectedChannelGroups:[]
}
```

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.