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

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格