I need some guidance whether I am doing this correct. Im trying to get a single object of a car. This is how I create a car:
car := &types.Car{
Model: req.Model,
Regnr: req.Regnr,
Year: req.Year,
Type: req.Type,
CreationTime: time.Now(),
Sold: false,
}
//key := datastore.NewKey(context, "Car", "", 0, nil)
_, err := datastore.Put(context, datastore.NewIncompleteKey(context, "Car", nil), car)
This is the way im trying to get the car again.
vars := mux.Vars(r)
regnr := vars["regnr"]
car := types.Car{}
carKey := datastore.NewKey(context, "Car", regnr, 0, nil)
err := datastore.Get(context, carKey, &car)
if err != nil {
log.Println("error getting car", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
But I get the error: "error getting car datastore: no such entity"
I know I can do a GetAll and limit to one. But if im deleting an object, I need the entity. I guess. So I want to do it right.
Thanks!