我通过命令govendor init
和govendor fetch "github.com/gorilla/mux"
创建了项目中的供应商目录。
但是,在gcloud gcloud app deploy
中执行部署时会发生以下错误,无法找到github.com/gorilla/mux
:
错误:(gcloud.app.deploy)错误响应:9部署包含无法编译的文件:编译失败: /work_dir/main.go:5:5:无法找到导入:"github.com/gorilla/mux“
缺少什么来使部署工作?我的计划是免费的
app.yaml
service: api
runtime: go
api_version: go1
handlers:
- url: /sample
script: _go_app
main.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()
}
发布于 2019-02-01 22:34:16
如果您想使用这个mux包的版本,那么请确保示例-API文件在Go工作区中。
如果不需要监控,请删除供应商目录,运行go get github.com/gorilla/mux
,然后部署应用程序。在这种情况下,应用程序文件不需要在工作区中。
除了这些与构建相关的问题之外,您还必须向http.DefaultServeMux注册Gorilla。
func init(){
r := mux.NewRouter()
r.HandleFunc("/sample", GetInfo)
http.Handle("/", r)
}
https://stackoverflow.com/questions/54486017
复制相似问题