我正在编写的一个简单的 Go GAE(灵活)应用程序在我引入 cloud.google.com 包以使用 Google 服务后无法立即部署。部署日志的片段:
...
golang.org/x/oauth2/google
# golang.org/x/oauth2/google
_gopath/src/golang.org/x/oauth2/google/appengine_hook.go:12: cannot use appengine.AccessToken (type func(appengine.Context, ...string) (string, time.Time, error)) as type func("golang.org/x/net/context".Context, ...string) (string, time.Time, error) in assignment
_gopath/src/golang.org/x/oauth2/google/appengine_hook.go:13: cannot use appengine.AppID (type func(appengine.Context) string) as type func("golang.org/x/net/context".Context) string in assignment
...
这可以通过go install -v -tags appenginevm
应用程序在本地复制以进行部署。appenginevm
该应用程序在没有标签的情况下构建并运行良好。
我刚刚按照 helloworld 示例进行了修改,但找不到其他有此问题的人(一些 Google 搜索没有任何用处)。
任何人都知道如何解决这个问题/我错过了什么?
提前致谢。完整的程序如下。
package main
import (
"context"
"fmt"
"log"
"net/http"
"time"
"cloud.google.com/go/storage"
)
var (
client *storage.Client
)
func main() {
ctx := context.Background()
var err error
client, err = storage.NewClient(ctx)
if err != nil {
log.Fatal(err)
return
}
defer client.Close()
http.HandleFunc("/_ah/health", healthCheckHandler)
http.HandleFunc("/", indexHandler)
log.Print("Listening on http://localhost:8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
func httpError(w http.ResponseWriter, err error) {
log.Println(err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "OK")
}
func indexHandler(w http.ResponseWriter, r *http.Request) {
start := time.Now()
finish := time.Since(start)
fmt.Fprintf(w, "Done %v %v", finish)
}
这里是app.yaml
env: flex
runtime: go