Server SDK
Go SDK
The Go SDK wraps the Radist HTTP API with idiomatic Go conventions. Use it to create P2P calls and SFU rooms from any Go service.
Install
Shell
go get github.com/klirix/radist/sdks/go-serverConstructor
radist.NewClient(secretToken, ...opts) returns a configured client. Pass options with radist.WithProjectID(), radist.WithAPIBaseURL(), or radist.WithHTTPClient().
| Option | Description |
|---|---|
| WithProjectID(id string) | Set the project id used for all requests. |
| WithAPIBaseURL(url string) | Override the default API base URL (useful for testing). |
| WithHTTPClient(c *http.Client) | Provide a custom HTTP client with timeouts or middleware. |
API surface
| Method | Returns | Description |
|---|---|---|
| CreateP2PConnection(ctx, opts) | P2PConnection, error | Creates a two-peer call and returns two participant tokens. Pass &CreateP2PConnectionOptions{AccessControl: "public"} for a public call; defaults to "private". |
| CreateRoom(ctx, opts) | Room, error | Creates an SFU room and returns two room tokens. |
| MintConnectionToken(ctx, opts) | ConnectionToken, error | Mints an extra participant token for an existing call or room. |
Access control
Calls are private by default: only tokens minted server-side with your secret
key are accepted. Pass nil (or omit AccessControl) for a private
call. Set AccessControl: "public" to allow anyone with your public key to join.
Go
// Private (default) — only your server can mint tokens:
conn, err := client.CreateP2PConnection(ctx, nil)
// Public — anyone with your public key can join via the easy interface:
conn, err := client.CreateP2PConnection(ctx, &radist.CreateP2PConnectionOptions{
AccessControl: "public",
})
// For private calls, mint additional tokens as needed:
token, err := client.MintConnectionToken(ctx, radist.MintConnectionTokenOptions{
CallID: conn.CallID,
})
fmt.Println("extra token:", token.ConnectionToken)Create a P2P call
Go
package main
import (
"context"
"fmt"
"log"
radist "github.com/klirix/radist/sdks/go-server"
)
func main() {
client, err := radist.NewClient("rad_sk_your_secret_key",
radist.WithProjectID("your_project_id"),
)
if err != nil {
log.Fatal(err)
}
// Pass nil to use all defaults (access control defaults to "private").
conn, err := client.CreateP2PConnection(context.Background(), nil)
if err != nil {
log.Fatal(err)
}
fmt.Println("call id:", conn.CallID)
fmt.Println("tokens:", conn.CallTokens)
fmt.Println("access control:", conn.AccessControl)
}Create an SFU room
Go
conn, err := client.CreateRoom(context.Background(), radist.CreateRoomOptions{})
if err != nil {
log.Fatal(err)
}
fmt.Println("room id:", conn.RoomID)
fmt.Println("room tokens:", conn.RoomTokens)Mint a connection token
Go
// Mint a token for an existing P2P call
result, err := client.MintConnectionToken(context.Background(), radist.MintConnectionTokenOptions{
CallID: "550e8400-e29b-41d4-a716-446655440000",
})
// Or mint a token for an SFU room
result, err := client.MintConnectionToken(context.Background(), radist.MintConnectionTokenOptions{
RoomID: "room_abc123",
})
fmt.Println("token:", result.ConnectionToken)Error handling
API errors are returned as *radist.APIError with Status int and Message string fields.
Go
conn, err := client.CreateP2PConnection(ctx, radist.CreateP2PConnectionOptions{})
if err != nil {
var apiErr *radist.APIError
if errors.As(err, &apiErr) {
fmt.Printf("API error %d: %s
", apiErr.Status, apiErr.Message)
}
log.Fatal(err)
}