Example GoLang Code for Push Notifications Using OneSignal?

I’m trying to send Push Notifications from the GoLang Runtime to my Unity client. I’ve set everything up correctly and can make an iOS build and send a push notification to it from the OneSignal dashboard. I’m not sure how to do that with the GoLang runtime though. Can anyone point me in the right direction or give me some example code ? Thanks !

I’m getting somewhere … it looks like I need to implement the OneSignal Go SDK from here:

I’ve added the following line to my go.mod file:

github.com/OneSignal/onesignal-go-api v1.0.4

For some reason, Visual Code won’t let me specify the latest v2.0.1 Whenever I try to change v1.0.4 to v2.0.1 in the go.mod file and hover my mouse pointer over the error, the editor says “version “v2.0.1” invalid: v0 or v1, not v2: syntax” Does anybody know why ?

Then when I try to launch with Docker, my module builds okay, but then it says:

nakama-nakama-1       | {"level":"error","ts":"2023-07-30T00:41:44.769Z","caller":"server/runtime_go.go:2739","msg":"Could not open Go module","path":"data/modules/backend.so","error":"plugin.Open(\"data/modules/backend\"): plugin was built with a different version of package golang.org/x/net/context/ctxhttp"}
nakama-nakama-1       | {"level":"error","ts":"2023-07-30T00:41:44.769Z","caller":"server/runtime.go:636","msg":"Error initialising Go runtime provider","error":"plugin.Open(\"data/modules/backend\"): plugin was built with a different version of package golang.org/x/net/context/ctxhttp"}
nakama-nakama-1       | {"level":"fatal","ts":"2023-07-30T00:41:44.769Z","caller":"main.go:158","msg":"Failed initializing runtime modules","error":"plugin.Open(\"data/modules/backend\"): plugin was built with a different version of package golang.org/x/net/context/ctxhttp"}

It was working fine before I added the OneSignal stuff.

I think I’ve fixed it by downloading the Nakama source, opening the go.mod and copying the golang.org/x/oauth2 line into my own go.mod file. Not sure what version of Nakama I’m using but in my case it was this:

golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094 // indirect

and to fix the OneSignal thing to use v2.01 I changed my go.mod file to this:

github.com/OneSignal/onesignal-go-api/v2 v2.0.1

Then lots of go mod vendor and go mod tidy and followed any prompts to download various things but got there in the end. Hopefully it’s as easy to do that on my production server as it was on my Windows local machine using Docker.

Well, thanks for the help everyone :wink: I’ll mark this as solved and leave it here to help anyone else who has the same problem implementing OneSignal. Hope I haven’t spoken too soon but I’ve copied the OneSignal example code into my Go module and it builds okay.