forked from GoogleCloudPlatform/golang-samples
/
modules.go
39 lines (31 loc) · 859 Bytes
/
modules.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package counter
// [START push_queues_and_backends]
import (
"net/http"
"net/url"
"google.golang.org/appengine"
"google.golang.org/appengine/taskqueue"
)
func pushHandler(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
key := r.FormValue("key")
// Create a task pointed at a backend.
t := taskqueue.NewPOSTTask("/path/to/my/worker/", url.Values{
"key": {key},
})
host, err := appengine.ModuleHostname(ctx, "backend1", "", "")
if err != nil {
// Handle err
}
t.Header = http.Header{
"Host": {host},
}
// Add the task to the default queue.
if _, err := taskqueue.Add(ctx, t, ""); err != nil {
// Handle err
}
}
// [END push_queues_and_backends]