【问题标题】:In deploy gcloud is not encountering the vendor dependencies在部署 gcloud 中没有遇到供应商依赖项
【发布时间】:2019-06-26 09:58:15
【问题描述】:

我通过命令govendor initgovendor fetch "github.com/gorilla/mux"创建了项目中的vendor目录。

但是,在 gcloud gcloud app deploy 中执行部署时出现以下错误,github.com/gorilla/mux 找不到:

错误:(gcloud.app.deploy)错误响应:[9]部署包含无法编译的文件:编译失败: /work_dir/main.go:5:5:找不到导入:“github.com/gorilla/mux”

部署工作缺少什么?我的计划在 gcloud 中是免费的

app.yaml

service: api
runtime: go
api_version: go1

handlers:
- url: /sample
  script: _go_app

ma​​in.go

package main

import (
    "encoding/json"
    "github.com/gorilla/mux"
    "net/http"
    "google.golang.org/appengine"
)

type Foo struct {
    Text string `json:"text"`
}

func GetInfo(w http.ResponseWriter, r *http.Request) {
    json.NewEncoder(w).Encode(Foo{"hello"})
}

func init(){
    r := mux.NewRouter()
    r.HandleFunc("/sample", GetInfo)
}

func main() {
    appengine.Main()
}

【问题讨论】:

    标签: go gcloud vendor


    【解决方案1】:

    如果您想使用您的 mux 包的供应商版本,请确保 SAMPLE-API 文件位于 Go workspace 中。

    如果不需要供应商,则删除供应商目录,运行go get github.com/gorilla/mux,然后部署您的应用程序。在这种情况下,您的应用程序文件不需要位于工作区中。

    除了这些与构建相关的问题外,您还必须使用 http.DefaultServeMux 注册 Gorilla mux。

    func init(){
        r := mux.NewRouter()
        r.HandleFunc("/sample", GetInfo)
        http.Handle("/", r)
    }
    

    【讨论】:

    • 无效,出现404 page not found。我执行了命令go get github.com/gorilla/mux
    • 您具体做了什么导致找不到 404 页面?
    • 我运行go get github.com/gorilla/mux 命令,然后运行gcloud app deploy 然后我进入浏览器并输入地址http://api.testcaixa-803f4.appspot.com/samplelocalhost 有效...
    • localhost 它可以工作,但需要http.ListenAndServe(":8000", r)这一行
    • 查看更新的答案。使用dev_appserver.py 在本地运行服务器。它将帮助您在部署之前发现这些问题。
    猜你喜欢
    • 2018-08-20
    • 1970-01-01
    • 1970-01-01
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2019-03-07
    • 2019-08-28
    相关资源
    最近更新 更多