timehop / apns

A Go package to interface with the Apple Push Notification Service
https://godoc.org/github.com/timehop/apns
MIT License
185 stars 47 forks source link

Move away from pointers for badge field? #38

Closed nathany closed 8 years ago

nathany commented 9 years ago

The only problem with using a series of pointers in structs is they can end in race conditions if any goroutines mutate the underlying pointer.

For that reason, I took the same approach here for omitempty badges: https://github.com/joekarl/go-libapns/pull/8

It's not "pretty" but it's thread-safe. @themartorana

nathany commented 9 years ago

This would be similar to the NullInt64 type in the sql package. :+1:

taylortrimble commented 9 years ago

:+1:

nathany commented 9 years ago

Before the PR from @themartorana, go-libapns was just using -1 to reset the badge rather than 0 (which is omitted, meaning no change).

anachronistic/apns uses an interface for different types of Alerts. That could be another option for the badge.

themartorana commented 9 years ago

The biggest issue I had with -1 is that the struct is initialized with 0, a valid (and badge-clearing) value. So unless you hide the struct but give it a public initializer method, its default state is to clear the badge.

themartorana commented 9 years ago

Ping on this - looks like we're still using a pointer. I can quickly submit a NullInt64-esque solution like https://github.com/joekarl/go-libapns/pull/8 (my preferred method). Thoughts?

taylortrimble commented 9 years ago

Go for it!

On Thu, Sep 3, 2015 at 12:32 PM, David Martorana notifications@github.com wrote:

Ping on this - looks like we're still using a pointer. I can quickly submit a NullInt64-esque solution like https://github.com/joekarl/go-libapns/pull/8 (my preferred method). Thoughts?

Reply to this email directly or view it on GitHub: https://github.com/timehop/apns/issues/38#issuecomment-137550321

nathany commented 8 years ago

closed with #60