当我试图在golang App Engine中使用onesignal enviorment实现推送通知时,但iam出错“http.DefaultTransport和http.DefaultClient不是在App Engine中可用”。这是我的代码,https://onesignal.com/api/v1//notifications:http.DefaultTransport和http.DefaultClient在App Engine中不可用
func (c *PushNotificationController) CreateNotification() {
client := onesignal.NewClient(nil)
client.AppKey = "MyAppKey"
client.UserKey = "MyUserKey"
notifID := CreateNotifications(client)
log.Println(notifID)
}
func CreateNotifications(client *onesignal.Client) string {
playerID := "SamplePlayerId" // valid
notificationReq := &onesignal.NotificationRequest{
AppID: "MyAppKey",
Contents: map[string]string{"en": "English message"},
IsIOS: true,
IncludePlayerIDs: []string{playerID},
}
if createRes, res, err := client.Notifications.Create(notificationReq){
if err != nil {
log.Fatal(err)
}
return createRes.ID
}
...
}
有什么办法可以使软件包应用引擎兼容?该包用于使用oneignal发送推送通知 –
@farsanapb应通过上下文传递上下文:'c:= appengine.NewContext(r)' 这个'r'是请求对象。所以为NewXXX添加context.Context似乎对我来说是个好主意。 – mattn