如何正确导入Golang appengine? [英] How to correctly import Golang appengine?

查看:1845
本文介绍了如何正确导入Golang appengine?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 导入appengine / datastore$ b在我的Google App Engine项目中, $ b  

成功了很长时间,假设导入定位到我拥有App Engine SDK的东西。不过,现在我还要使用来自Google的第三方图书馆,这些图书馆也使用App Engine的内容,但使用完整路径导入:

  importgoogle.golang.org/appengine

运行应用程序

  $ goapp serve 

失败,找不到appengine:

  ... go / src / golang.org / x / oauth2 / client_appengine.go :16:找不到导入:google.golang.org/appengine/urlfetch

在$ GOPATH
中找不到包google.golang.org/appengine / code>

显然,我想使用相同的App Engine零件没有其他问题。我的第一个例子是我想告诉第三方图书馆使用App Engine SDK库,但是我不知道导入中有不同的前缀。



我应该在项目中使用所有App Engine导入的完整路径吗?这与我在Google的Google App Engine for Golang网页上阅读的内容相反。例如。 此处



一般来说,设置东西的方法是什么,以便在App Engine和第三方库中开发和生产时都能找到合适的appengine库?



提前感谢任何帮助!



更新



我可以也可以看到,在添加第三方库并运行 go get 之后,它将各种东西提取到$ code> $ GOPATH / src / google.golang.org / API /...。许多东西在那里,appengine以及其他似乎都是Golang的Google API ...!



所以没有解决,但是我了解到有一个变化更改为完全合格的appengine导入路径



现在,当我拉入新的应用程序时,我的应用程序在本地运行,以满足使用新导入路径的oauth库。

  go get google.golang.org/appengine 

根据这个



如果您不想更新整个应用程序要使用新的App Engine软件包,您可以并行使用这两套软件包,只使用带有oauth2软件包的新软件包。



其实很混乱当我部署在App Engine上时,我不知道可用的内容。有人知道吗?

解决方案

就像你的更新说的一样;您可以使用两种类型的并行导入(在相同的代码块中),而他们不赞成使用旧的API并完成新的API:


大多数App Engine服务都具有完全相同的API。一些API被清理了,有些还没有被使用。


,从您的一个链接中进一步下降) / p>

如果您需要同时使用 appengine google.golang.org/appengine 那么你可以别名导入路径使之成为可能。如下所示:

  import(
oldAppengineappengine
google.golang.org/appengine

或任何您想要的名字。



如果您部署时无法使用,您将在构建时遇到错误,并且不会部署到App Engine,因此您不用担心。


In my Google App Engine project written in Go I've been using e.g.

import "appengine/datastore"

with success for a long time and assuming the import locates things where I have the App Engine SDK. However, now I want to use a third party library also from Google that uses things from App Engine as well, but imports with the full path:

import "google.golang.org/appengine"

Running the app

$ goapp serve

fails with not finding appengine:

...go/src/golang.org/x/oauth2/client_appengine.go:16: can't find import: "google.golang.org/appengine/urlfetch"

Can't find package "google.golang.org/appengine" in $GOPATH

Obviously I want to use the same App Engine parts to not have other problems. My first through is that I want to tell the third party library to use the App Engine SDK libraries, but I don't know how as it has a different prefix in the import.

Should I use the full path in my project for all App Engine imports? This would be opposite to what is in all what I have read on the Google's App Engine for Golang webpages. E.g. here.

Generally, what is the way to set up things so that it finds the right appengine libraries both in development and production on App Engine as well as from third party libraries?

Thanks in advance for any help!

UPDATE

I can also see that after adding the third party library and running go get it fetched all kinds of stuff into $GOPATH/src/google.golang.org/api/.... Lots of stuff there and appengine as well etc. It seems to be all Golang Google APIs...!

So it's not resolved but I have learned that there's a change that changes to fully qualified appengine import paths.

Now I have my app running locally as I pulled in the new appengine to satisfy the oauth library that uses the new import paths.

go get google.golang.org/appengine

According to this:

If you don't want to update your entire app to use the new App Engine packages, you may use both sets of packages in parallel, using only the new packages with the oauth2 package.

Actually very confusing and I don't know what is available when I deploy on App Engine. Does anyone know?

解决方案

It's like your update says; you can use both types of imports in parallel (in the same chunk of code) while they're deprecating the old API and finishing up the new one:

Most App Engine services are available with exactly the same API. A few APIs were cleaned up, and some are not available yet.

(source, a little further down from one of your links)

If you need to use both appengine and google.golang.org/appengine then you can alias the import paths to make this possible. Something like:

import (
   oldAppengine "appengine"
   "google.golang.org/appengine"
)

Or whatever you want to name them.

If something's not available when you deploy, you'll get errors on build and it won't deploy to App Engine, so you don't have to worry about it.

这篇关于如何正确导入Golang appengine?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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