duanchandun1860 2019-02-01 19:28
浏览 95
已采纳

在部署中,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()
}
  • 写回答

1条回答 默认 最新

  • dongpu42006096 2019-02-01 22:34
    关注

    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)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 能给我一些人生建议吗
  • ¥15 mac电脑,安装charles后无法正常抓包
  • ¥18 visio打开文件一直显示文件未找到
  • ¥15 请教一下,openwrt如何让同一usb储存设备拔插后设备符号不变?
  • ¥30 使用quartz框架进行分布式任务定时调度,启动了两个实例,但是只有一个实例参与调度,另外一个实例没有参与调度,不知道是为什么?请各位帮助看一下原因!!
  • ¥50 怎么获取Ace Editor中的python代码后怎么调用Skulpt执行代码
  • ¥30 fpga基于dds生成幅值相位频率和波形可调的容易信号发生器。
  • ¥15 R语言shiny包和ncdf4包报错
  • ¥15 origin绘制有显著差异的柱状图和聚类热图
  • ¥20 simulink实现滑模控制和pid控制对比,提现前者优势