go-libapns

A low level APNS library for Go with an emphasis on being fast and efficient

Warning!

While this library is (fairly) stable, it needs to be battle tested before really relying heavily on it. That being said, use it, break it, and I would love any testing that you can throw at it

When it comes to APNS libraries, most of them make some fatal mistakes. Those mistakes tend to boil down to: not handling the latest guidelines from Apple, relying on inefficient networking, or not handling errors in the ways Apple requires you to. go-libapns tries to be a simple low level interface that should be able to handle large amounts of push notifications in a CPU, Memory, and Network effecient manner. go-libapns also looks to be prepared for the future, with the impending expansion of the APNS payload and new fields, the code is mostly setup to handle these new featues.

Contributing

go-libapns is open source and the code is on github. Feel free to submit pull requests and bug reports.

Quickstart

Get the code
go get github.com/joekarl/go-libapns
Send push notifications!

Handling Errors

Due to Apple's streaming protocol, errors are a bit tricky to handle correctly. However by following a few simple guidelines, go-libapns will do the heavy lifting for you, allowing you to focus on what you want to do when an error occurs.

  1. Whenever you write to the SendChannel, you should also listen to the close channel. This is easy to do with a select.
  2. Even though go-libapns has accepted a message, it doesn't mean that message has been sent to Apple yet. You can flush the network by calling Disconnect() or by waiting a while to see if the close channel fires, but by far the best option is to listen to the close channel constantly and never manually close the connection.
  3. When the close channel fires, you'll get back a ConnectionClose object. This object will contain information about why the connection was closed, but more importantly it will give you back a list of unsent messages that you should attempt to resend.