I'm writing a simple App Engine program using Go. I need to write some data to Google DataStore. The program consistently hangs when I attempt to .Put the data into storage. This has bedeviled me this entire week.
At some point, I managed to write the data to DataStore, which I realized only once I discovered how to view the uploaded data within Cloud Console. I've changed the code a lot since then, and now I can no longer write any data. It hangs every time.
Logs show nothing helpful. Only a notice that the process has timed out. No logs written from the program, only from the system.
Process terminated because the request deadline was exceeded. (Error code 123)
I've tried changing import statements, using this link, but it failed to compile, so I went back to this link which compiles without issue.
I considered the possibility that I had somehow badly misconfigured (disfigured, perhaps?) my development environment, so I went to a clean machine and carefully went through a new install. It still hangs.
My app.yaml file:
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
An index.yaml file I added:
indexes:
- kind: Bacon
properties:
- name: YCode
direction: asc
- name: URL
- name: Owner
- name: Location
Here is my code:
package main
import (
"fmt"
"log"
"net/http"
"google.golang.org/appengine/datastore"
"google.golang.org/appengine"
)
type Bacon struct {
YCode string
URL string
Owner string
Location string
}
func main() {
http.HandleFunc("/", indexHandler)
appengine.Main()
}
func indexHandler(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
projectID := "fake-for-discussion-thread-787987"
client, err := datastore.NewClient(ctx, projectID)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
return
}
kind := "Bacon"
name := "3"
baconKey := datastore.NameKey(kind, name, nil)
//Make bacon
bacon := Bacon{
YCode: "1",
URL: "http://www.safeway.com",
Owner: "Bob",
Location: "Deli",
}
// I've confirmed that this is where it hangs every time.
// It doesn't even capture my silly fatal log entry.
// It just times out and finally sends a 500 Server Error.
if _, err := client.Put(ctx, baconKey, &bacon); err != nil {
log.Fatalf("Failed to save my Bacon: %v", err)
}
client.Close()
}
Many thanks for any help you can offer!