Skip to main content

Relay SDK for Go Lang

Getting Started

The Relay SDK for Go enables Go developers to connect and use SignalWire's Relay APIs within their own Go code. Our Relay SDK allows developers to build or add robust and innovative communication services to their applications.

The Relay SDK for Go is easy to use and only takes a few minute to setup and get running.

Installation

Install the package using "go get".

go get github.com/signalwire/signalwire-golang

Minimum Requirements

The Go SDK requires Go 1.11 or greater installed on your system.

Using the SDK

The Go SDK can be used to get up and running with Relay quickly and easily. In order to use the Go client, you must get your project and token from your SignalWire dashboard.

There are a few ways to get started, depending on your needs: Relay.Consumer, Relay.Task, and Relay.Client.

Relay Consumer

A Relay.Consumer creates a long running process, allowing you to respond to incoming requests and events in realtime. Relay Consumers abstract all the setup of connecting to Relay and automatically dispatches workers to handle requests; so you can concentrate on writing your code without having to worry about multi-threading or blocking, everything just works. Think of Relay Consumers like a background worker system for all your calling and messaging needs.

Relay Consumers can scale easily, simply by running multiple instances of your Relay.Consumer process. Each event will only be delivered to a single consumer, so as your volume increases, just scale up! This process works well whether you are using Docker Swarm, a Procfile on Heroku, your own webserver, and most other environments.

Setting up a new consumer is the easiest way to get up and running.

consumer := new(signalwire.Consumer)
// setup the Client
consumer.Setup(PProjectID, PTokenID, Contexts)
// register callback
consumer.Ready = MyReady
// start
if err := consumer.Run(); err != nil {
signalwire.Log.Error("Error occurred while starting Signalwire Consumer\n")
}

Learn more about Relay Consumers

Contexts

Relay uses Contexts as a simple way to separate events to specific consumers, allowing you to write consumers for specific types of calls or messages or scale them independently. A Context is simply a named string, that allows you to categorize requests. When creating outbound requests, or configuring phone numbers for inbound requests, you can specify the context; Relay will then deliver that call or event to Consumers that are configured to listen for that context.

For example, you could have a customer support phone number configured to send to Relay with the support context, and a personal number configured with personal context. Relay would deliver these events to any Consumer listening for those contexts. This gives you a lot of control in how messages are delivered to your Consumers, allowing you to write Consumer classes specific to the context, scale them independently, or separate traffic based on your own business rules.