Announcing The Official Golang Pusher Library

gopher.jpg

Go is an amazing and powerful language, and for a while we have been receiving a lot of requests from people we meet at events and through our support system about the possibility of using Pusher with Go. Given that it has established itself with an awesome community and increasing traction, there were a few \[…\]

Introduction

Go is an amazing and powerful language, and for a while we have been receiving a lot of requests from people we meet at events and through our support system about the possibility of using Pusher with Go. Given that it has established itself with an awesome community and increasing traction, there were a few questions as to why there was no official support yet implemented.

go-programming-language-pusher-library.jpeg

Up until now there have been a few libraries offering some support for interacting with our API, but we haven’t yet built a fully-fledged, consistently-maintained package. This has been unfortunate, given that Go is an awesome language that’s powerful and fun to write; and indeed, parts of our system are written in Go.

But now we are delighted to announce a new and official Pusher HTTP library for Go. This package allows you to interact with our API to trigger events, authenticate private and presence channels, validate webhooks, and query the state of your channels.

Getting Started

First of all, install the package:

$ go get github.com/pusher/pusher-http-go

Now let’s import it and initialize a client with your app credentials:

1package main
2
3import "github.com/pusher/pusher-http-go"
4
5func main(){
6
7  client := pusher.Client{
8    AppId: "your_app_id",
9    Key: "your_app_key",
10    Secret: "your_app_secret",
11  }
12
13}

In order to trigger an event, we pass to the Trigger method the channel, the name of the event and the data to send.

1data := map[string]string{"message": "hello world"}
2
3client.Trigger("test_channel", "my_event", data)

Now, open the Pusher Debug Console for your app via the Pusher dashboard and trigger the event to view the library in action!

Now, Over To You!

Of course, there’s a lot more you can do with this package beside triggering events. Check out the Github repo to view the full documentation, which includes a table with the all the supported features.

If you would like to contribute then dive right in, fork the repo, and start making some pull requests. Otherwise, if you use the Go library and make something awesome, then make sure to let us know!