AppEngine:找不到导入的"google.golang.org/appengine" [英] AppEngine: can't find import "google.golang.org/appengine"

查看:198
本文介绍了AppEngine:找不到导入的"google.golang.org/appengine"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在AppEngine上部署API,但不确定为什么它不起作用,这是代码的一部分:

package main 

import (
    "encoding/json"
    "io/ioutil"
    "net/http"
    "fmt"

    "google.golang.org/appengine"
)


func main () {
    InitPubSub()

    http.HandleFunc("/", HandlerBase)
    http.HandleFunc("/user", HandlerUser)
    http.HandleFunc("/event", HandlerEvent)

    appengine.Main()
}

尝试部署应用程序(gcloud应用程序部署)时出现以下错误: main.go:9:找不到导入:"google.golang.org/appengine"

我已遵循安装指南: https://cloud.google .com/appengine/docs/standard/go/download

并下载了appengine软件包:转到google.golang.org/appengine

谢谢!

解决方案

要运行go appengine项目,我发现单个服务的该项目结构绰绰有余.

your/project/path/src/mainapp.go
your/project/path/src/app.yaml
or
your/project/path/src/mainfolder/mainapp.go
your/project/path/src/mainfolder/app.yaml
your/project/path/src/lib/lib1/watever.go
your/project/path/src/lib/lib2/whatever2.go
your/project/path/src/google.golang.org/ - for the golang appengine package
your/project/path/src/golang.org/ - golang packages
your/project/path/src/github.org/ - github packages

子文件夹/程序包文件夹不得位于主app.yaml文件上方.此外,golang appengine程序包必须放在"src/"内部,并且只能直接从"google.golang.org"导入路径导入,而在其下方(而不是上方)可以导入.即,如果"app.yaml"文件直接位于src文件夹下:src/app.yaml-src/mainapp.go,则不允许"customFolder/google.golang.org",但允许"appengine".

I'm trying to deploy an API on AppEngine but I'm not sure why it's not working, here's an extract of the code:

package main 

import (
    "encoding/json"
    "io/ioutil"
    "net/http"
    "fmt"

    "google.golang.org/appengine"
)


func main () {
    InitPubSub()

    http.HandleFunc("/", HandlerBase)
    http.HandleFunc("/user", HandlerUser)
    http.HandleFunc("/event", HandlerEvent)

    appengine.Main()
}

I'm getting the following error when I try to deploy the app (gcloud app deploy): main.go:9: can't find import: "google.golang.org/appengine"

I've followed the installation guide: https://cloud.google.com/appengine/docs/standard/go/download

And downloaded the appengine package: go get google.golang.org/appengine

Thanks!

解决方案

To run a go appengine project, I found this project structure for a single service more than enough.

your/project/path/src/mainapp.go
your/project/path/src/app.yaml
or
your/project/path/src/mainfolder/mainapp.go
your/project/path/src/mainfolder/app.yaml
your/project/path/src/lib/lib1/watever.go
your/project/path/src/lib/lib2/whatever2.go
your/project/path/src/google.golang.org/ - for the golang appengine package
your/project/path/src/golang.org/ - golang packages
your/project/path/src/github.org/ - github packages

The subfolders/package folders, must not be above the main app.yaml file. Furthermore, the golang appengine package must be placed right inside "src/" and can only be imported directly from the "google.golang.org" import path and below that, not above. i.e. "customFolder/google.golang.org" is not allowed, "appengine", is however, allowed, provided that the app.yaml file is directly under src folder : src/app.yaml - src/mainapp.go.

这篇关于AppEngine:找不到导入的"google.golang.org/appengine"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆