Skip to main content

SDK overview

Preparation​

Pub/Sub currently supports Go SDK. To use Go SDK, complete the following prerequisites.

Get IAM access key​

To obtain a user authentication token (API authentication token), first create an access key and then retrieve the access key ID and secret access key.

caution

You can only access resources in the project associated with the issued access key.

  1. Go to KakaoCloud console > User profile > Credentials > IAM access keys.

  2. After creating the user access key, refer to Prepare API usage to retrieve the access key ID and secret access key.

SDK requirements​

Use Go SDK​

Ensure the following requirements are met to use the Go SDK.

  1. Install Go 1.25 or later, then download the Go SDK using the following commands.

    Download Go package
    wget https://objectstorage.kr-central-2.kakaocloud.com/v1/e9130193fc734337b2b0c1da50e44395/pubsub-sdk/go/v2.0.0/pubsub.tgz
    tar -xf pubsub.tgz

    cd {your-project}
    go mod edit -require pubsub-sdk-go@v0.0.0
    go mod edit -replace pubsub-sdk-go={pubsub-sdk-path}

    The downloaded SDK is release 2.0.0. Because its module path is pubsub-sdk-go without a /v2 suffix, use v0.0.0 as the local module placeholder and resolve it through replace to the downloaded directory.

    go.mod file results
    module ...

    require (
    pubsub-sdk-go v0.0.0
    )
    replace pubsub-sdk-go => {pubsub-sdk-path}
  2. Refer to Get IAM access key to issue credentials. The SDK authenticates with user access keys. Set the access key ID as CredentialID and the secret access key as CredentialSecret in the AccessKey type, as shown below.

    Example using credentials
    accessKey := pubsub.AccessKey{CredentialID: "credentialID", CredentialSecret: "credentialSecret"}
    opts := []option.ClientOption{
    option.WithAccessKey(accessKey),
    }
    client, err := pubsub.NewClient(ctx, opts...)
caution

You can only access resources in the project associated with the issued access key.

Client​

Use client objects to manage topics and subscriptions and to send and receive messages.

caution

You must release resources like threads used by the client object by calling the Close() method.

Configure custom settings​

Authentication and endpoint values are managed through ClientOption. Create ClientOption values when creating a client object to configure your own settings.

info

The default endpoint is set to the kr-central-2 region's endpoint.

MethodDescription
Close()Release resources such as threads
Client example
import (
"context"
"fmt"
"pubsub-sdk-go"
"pubsub-sdk-go/option"
)

func test(credentialID, credentialSecret string) error {
ctx := context.Background()
accessKey := pubsub.AccessKey{CredentialID: credentialID, CredentialSecret: credentialSecret}
opts := []option.ClientOption{
option.WithAccessKey(accessKey),
}
client, err := pubsub.NewClient(ctx, opts...)
if err != nil {
return fmt.Errorf("pubsub.NewClient: %v", err)
}

// do something

err = client.Close()
return err
}