Skip to content

Instantly share code, notes, and snippets.

@tenntenn
Last active August 10, 2017 02:25
Show Gist options
  • Save tenntenn/7d1b5ba754eb84704bfa9b55e46437cc to your computer and use it in GitHub Desktop.
Save tenntenn/7d1b5ba754eb84704bfa9b55e46437cc to your computer and use it in GitHub Desktop.
Google App Engine for GoがGo1.8に対応したので試してみた #golang #gcp ref: http://qiita.com/tenntenn/items/0b92fc089f8826fabaf1
$ gcloud components update
ls ~/Documents/go_appengine
BUGS VERSION bulkload_client.py download_appstats.py godoc goroot php_cli.py wrapper_util.pyc
LICENSE _python_runtime.py bulkloader.py endpointscfg.py gofmt goroot-1.6 run_tests.py
RELEASE_NOTES appcfg.py demos go-app-stager google goroot-1.8 tools
RELEASE_NOTES.python backends_conversion.py dev_appserver.py goapp gopath lib wrapper_util.py
func contextSet(r *http.Request, key, val interface{}) *http.Request {
if val == nil {
return r
}
return r.WithContext(context.WithValue(r.Context(), key, val))
}
func contextSet(r *http.Request, key, val interface{}) *http.Request {
if val == nil {
return r
}
return r.WithContext(context.WithValue(r.Context(), key, val))
}
$ goapp version
go version 1.6.4 (appengine-1.9.56) darwin/amd64
$ goapp env GOROOT
/Users/tenntenn/Documents/go_appengine/goroot-1.6
application: my-project-id
module: default
runtime: go
api_version: go1.8
version: main
handlers:
- url: /.*
script: _go_app
secure: always
application: my-project-id
module: default
runtime: go
api_version: go1.8
version: main
handlers:
- url: /.*
script: _go_app
secure: always
$ goapp version
go version 1.8.3 (appengine-1.9.56) darwin/amd64
$ goapp env GOROOT
/Users/tenntenn/Documents/go_appengine/goroot-1.8
$ go tool fix -force=context main.go
func DoSomething(f func(c context.Context) {// contextはgolang.org/x/net/contextだとする
}
func DoSomething(f func(c context.Context) {// contextはgolang.org/x/net/contextだとする
}
var slice []context.Context
var m map[*http.Request]context.Context
var slice []context.Context
var m map[*http.Request]context.Context
package hello
import (
"io"
"net/http"
"github.com/gorilla/mux"
"google.golang.org/appengine"
"google.golang.org/appengine/log"
)
func init() {
mx := mux.NewRouter()
mx.HandleFunc("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
log.Debugf(ctx, "time to say hello!")
io.WriteString(w, "howdy!")
}))
http.Handle("/", mx)
}
package hello
import (
"io"
"net/http"
"github.com/gorilla/mux"
"google.golang.org/appengine"
"google.golang.org/appengine/log"
)
func init() {
mx := mux.NewRouter()
mx.HandleFunc("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
log.Debugf(ctx, "time to say hello!")
io.WriteString(w, "howdy!")
}))
http.Handle("/", mx)
}
var ctxs = struct {
sync.Mutex
m map[*http.Request]*context
bg *context // background context, lazily initialized
// dec is used by tests to decorate the netcontext.Context returned
// for a given request. This allows tests to add overrides (such as
// WithAppIDOverride) to the context. The map is nil outside tests.
dec map[*http.Request]func(netcontext.Context) netcontext.Context
}{
m: make(map[*http.Request]*context),
}
var ctxs = struct {
sync.Mutex
m map[*http.Request]*context
bg *context // background context, lazily initialized
// dec is used by tests to decorate the netcontext.Context returned
// for a given request. This allows tests to add overrides (such as
// WithAppIDOverride) to the context. The map is nil outside tests.
dec map[*http.Request]func(netcontext.Context) netcontext.Context
}{
m: make(map[*http.Request]*context),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment