duanchandun1860 2019-02-01 11: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 14: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)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部