Last active
August 10, 2017 02:25
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gcloud components update |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func contextSet(r *http.Request, key, val interface{}) *http.Request { | |
if val == nil { | |
return r | |
} | |
return r.WithContext(context.WithValue(r.Context(), key, val)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func contextSet(r *http.Request, key, val interface{}) *http.Request { | |
if val == nil { | |
return r | |
} | |
return r.WithContext(context.WithValue(r.Context(), key, val)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ goapp version | |
go version 1.6.4 (appengine-1.9.56) darwin/amd64 | |
$ goapp env GOROOT | |
/Users/tenntenn/Documents/go_appengine/goroot-1.6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application: my-project-id | |
module: default | |
runtime: go | |
api_version: go1.8 | |
version: main | |
handlers: | |
- url: /.* | |
script: _go_app | |
secure: always |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application: my-project-id | |
module: default | |
runtime: go | |
api_version: go1.8 | |
version: main | |
handlers: | |
- url: /.* | |
script: _go_app | |
secure: always |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ goapp version | |
go version 1.8.3 (appengine-1.9.56) darwin/amd64 | |
$ goapp env GOROOT | |
/Users/tenntenn/Documents/go_appengine/goroot-1.8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go tool fix -force=context main.go |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func DoSomething(f func(c context.Context) {// contextはgolang.org/x/net/contextだとする | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func DoSomething(f func(c context.Context) {// contextはgolang.org/x/net/contextだとする | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var slice []context.Context | |
var m map[*http.Request]context.Context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var slice []context.Context | |
var m map[*http.Request]context.Context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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