From a7b3213140dccebbc62f98dbb7862f62f6bb6d0f Mon Sep 17 00:00:00 2001 From: William Shepherd Date: Wed, 21 Sep 2022 14:32:02 -0500 Subject: [PATCH] Fix undefined variable bug See [issue#2](https://github.com/OneSignalDevelopers/OneSignal-Go-Sample/issues/2) for more details --- lib/notification.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/notification.go b/lib/notification.go index b638497..11caf3c 100644 --- a/lib/notification.go +++ b/lib/notification.go @@ -10,17 +10,22 @@ import ( var configuration = onesignal.NewConfiguration() var apiClient = onesignal.NewAPIClient(configuration) -var osAuthCtx = context.WithValue( - context.Background(), - onesignal.AppAuth, - os.Getenv("REST_API_KEY"), -) func PushNotification() { - fmt.Fprintf(os.Stdout, "oAuthCtx: %v\n", osAuthCtx) - - notification := *onesignal.NewNotification(os.Getenv("APP_ID")) + appId := os.Getenv("APP_ID") + restApiKey := os.Getenv("REST_API_KEY") + osAuthCtx := context.WithValue( + context.Background(), + onesignal.AppAuth, + restApiKey, + ) + + notification := *onesignal.NewNotification(appId) notification.SetIncludedSegments([]string{"Subscribed Users"}) + notification.SetIsIos(false) + message := "Go Test Notification" + stringMap := onesignal.StringMap{En: &message} + notification.Contents = *onesignal.NewNullableStringMap(&stringMap) resp, r, err := apiClient.DefaultApi.CreateNotification(osAuthCtx).Notification(notification).Execute() @@ -31,4 +36,5 @@ func PushNotification() { } fmt.Fprintf(os.Stdout, "Response from `CreateNotification`: %v\n", resp) + fmt.Fprintf(os.Stdout, "Notification ID: %v\n", resp.GetId()) }