ctx := appengine.NewContext(r) q := datastore.NewQuery("User").Filter("name =", "John") users := make([]*User, 0) _, err := q.GetAll(ctx, &users) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return }
func handler(w http.ResponseWriter, r *http.Request) { ctx := appengine.NewContext(r) u := user.Current(ctx) if u == nil { url, _ := user.LoginURL(ctx, r.URL.String()) w.Header().Set("Location", url) w.WriteHeader(http.StatusFound) return } // User is logged in // ... }In this example, the `user.Current` function is called to get the current logged-in user. If the user is not logged in, the `user.LoginURL` function is called to redirect the user to the login page. The context is used to retrieve information about the current request and user. Package library: google.golang.org/appengine/aetest.