Skip to main content

Go

info

There is a newer currently undocumented GoLang library available here.

syntropy-pubsub-go is a Golang library designed specifically for the Synternet Data Layer project. With this library, you can effortlessly subscribe to existing data streams or publish new ones. Powered by the NATS messaging system, syntropy-pubsub-go offers seamless integration between your Golang applications and the Synternet Data Layer platform.

Installation

To install the Golang SDK for Data Layer, you can use Go modules or include it as a dependency in your project. Here's an example of how to add it to your project:

go get github.com/synternet/pubsub-go

Make sure to import the package in your code:

import "github.com/synternet/pubsub-go"

Getting Started

Before you start using the Golang SDK, make sure you have the necessary credentials and access tokens from the Synternet Developer Portal platform. These credentials will allow you to connect to the Data Layer and subscribe to the desired data streams.

Usage

  1. Initialize the SDK:
client, err := pubsub.NewClient("your-access-token", "your-private-key")
if err != nil {
log.Fatal("Failed to initialize the Data Layer client:", err)
}
  1. Subscribe to a Data Stream:
stream, err := client.Subscribe("stream-name")
if err != nil {
log.Fatal("Failed to subscribe to the data stream:", err)
}
  1. Receive Data Stream Events:
go func() {
for event := range stream.Events() {
// Handle the data stream event
fmt.Println("Received event:", event)
}
}()
  1. Publish Data to a Stream:
err = client.Publish("stream-name", []byte("Hello, Data Layer!"))
if err != nil {
log.Fatal("Failed to publish data to the stream:", err)
}

Examples

For detailed usage examples, please refer to the examples directory in the repository. These examples cover various scenarios and demonstrate how to utilize the SDK's features effectively.

Support

If you encounter any difficulties or have questions regarding the Golang SDK for Data Layer, please reach out to our support team at Discord #developer-discussion. We are here to assist you and ensure a smooth experience with our SDK.

We hope this documentation provides you with a comprehensive understanding of the Golang SDK for the Data Layer. Happy coding with real-time data streams and enjoy the power of the Data Layer in your Golang applications!