Skip to content

datastore error - not an App Engine contex #167

@cn0047

Description

@cn0047

I'm trying to upgrade my project from go1 to go111.
In my project I'm using datastore, here you can see how my code looks:

package controller

import (
	"google.golang.org/appengine/datastore"
	"log"
	"net/http"
	"time"
)

type Measurement struct {
	Project      string    `datastore:"project"`
	At           time.Time `datastore:"at"`
	Took         int       `datastore:"took,noindex"`
	ResponseCode int       `datastore:"responseCode"`
}

func MeasurementController(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()

	query := datastore.NewQuery("Measurement")
	data := make([]Measurement, 0)

	keys, err := query.GetAll(ctx, &data)
	if err != nil {
		log.Printf("Error %#v", err)
		return
	}

	log.Printf("Keys: %+v, Data: %+v", keys, data)
}

And I always get error: Error: &errors.errorString{s:"not an App Engine context"}
As you can see I've already replaced ctx := appengine.NewContext(r) to ctx := r.Context()
but it won't work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions