在部署中,gcloud没有遇到供应商依赖性

在部署中,gcloud没有遇到供应商依赖性

问题描述:

I created by the commands govendor init and govendor fetch "github.com/gorilla/mux" the vendor directory in the project.

enter image description here

However, when performing deploy in gcloud gcloud app deploy the following error occurs, github.com/gorilla/mux is not found:

ERROR: (gcloud.app.deploy) Error Response: [9] Deployment contains files that cannot be compiled: Compile failed: /work_dir/main.go:5:5: can't find import: "github.com/gorilla/mux"

What is missing to make deploy work? My plan is free in gcloud

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()
}

我是通过命令 govendor init code>和 govendor创建的,提取“ github.com / gorilla / mux“ code>项目中的供应商目录。 p>

“在此处输入图片描述” p>

但是,在gcloud gcloud app deploy code>中执行部署时,会发生以下错误,找不到 github.com/gorilla/mux code>: p>

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

要使部署正常工作需要缺少什么? 我的计划在gcloud中免费 p>

app.yaml strong> p>

  service:api 
runtime:go 
api_version  :go1 
 
handlers:
-网址:/ sample 
脚本:_go_app 
  code>  pre> 
 
 

main.go strong> p>

 包main 
 
import(
“ encoding / json” 
“ github.com/gorilla/mux"
” net / http“ 
” google.golang.org  / appengine“ 
)
 
type Foo结构{
文本字符串`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)
} \  n 
func main(){
 appengine.Main()
} 
  code>  pre> 
  div>

If you want to use your vendored version of the mux package, then ensure that the SAMPLE-API files are in a Go workspace.

If vendoring is not required, then delete the vendor directory, run go get github.com/gorilla/mux and then deploy your app. In this case, your application files do not need to be in a workspace.

In addition to these build related issues, you must register the Gorilla mux with http.DefaultServeMux.

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