错误导入 “syscall” 用于云存储 API。

huangapple go评论80阅读模式
英文:

bad import "syscall" for cloud storage APIs

问题

我正在按照https://cloud.google.com/appengine/docs/go/googlecloudstorageclient/download上的说明进行操作,尝试将一些代码从已弃用的Files API迁移到新的Cloud Storage API,但没有成功。

我正在按照以下步骤进行操作...

我正在运行appengine v1.9.23,这个版本比所需的appengine v1.8.1要新。

我的$GOPATH已经设置好了,所以我跳过了第一步。

我继续进行第二步:

goapp get -u golang.org/x/oauth2

goapp get -u google.golang.org/cloud/storage

我没有在托管的VM上进行开发,所以我跳过了第三步。

现在当我运行应用程序时,我得到了以下错误:

go-app-builder: Failed parsing input: parser: bad import "syscall" in goapp/src/golang.org/x/net/internal/nettest/error_posix.go

我做错了什么?


重现步骤

  • 从https://console.cloud.google.com/storage/browser/appengine-sdks/featured/下载并安装Google Appengine运行时版本1.9.23。按照https://cloud.google.com/appengine/downloads?hl=en上的安装说明进行操作。

  • 创建一个appengine项目目录:

% mkdir $HOME/myapp

  • 创建一个名为~/myapp/app.yaml的新的app.yaml文件。详细信息请阅读Google网站上的说明:https://cloud.google.com/appengine/docs/go/config/appconfig

我使用的是没有静态资源的版本:

application: myapp
version: alpha-001
runtime: go
api_version: go1

handlers:
- url: /.*
  script: _go_app
  • 创建一个用于存放Go源文件的位置。

% mkdir $HOME/myapp/go

  • 将GOPATH设置为源文件的位置

% export GOPATH=$HOME/myapp/go

  • 获取Go appengine示例项目:https://github.com/golang/example

% goapp get github.com/golang/example/appengine-hello

此命令将把示例应用程序下载到GOPATH中的第一个路径条目中。

  • 按照https://cloud.google.com/appengine/docs/go/googlecloudstorageclient/download中的说明安装Google Cloud Storage客户端库。有关详细信息,请参考本问题顶部的步骤。按照说明操作应该会运行2个命令:

% go get -u golang.org/x/oauth2

% go get -u google.golang.org/cloud/storage

  • 尝试运行您的Go应用程序

% goapp serve

您将看到以下编译错误(没有堆栈跟踪):

2015/12/23 10:37:07 go-app-builder: Failed parsing input: parser: bad import "syscall" in go/src/golang.org/x/net/ipv6/control_unix.go

英文:

I am following the instructions on https://cloud.google.com/appengine/docs/go/googlecloudstorageclient/download to begin migrating some code from the, now deprecated, Files API to the new Cloud Storage API without success.

The steps I'm following are ...

I'm running appengine v1.9.23 which is later than the required appengine v1.8.1.

My $GOPATH is set, so I skip step #1.

I proceed to step #2:

goapp get -u golang.org/x/oauth2

goapp get -u google.golang.org/cloud/storage

I am not developing on a managed VM, so I skip step #3.

Now when I run the application, I get:

go-app-builder: Failed parsing input: parser: bad import "syscall" in goapp/src/golang.org/x/net/internal/nettest/error_posix.go

What am I doing wrong?


Steps to reproduce

% mkdir $HOME/myapp

I use a version that does not have the static resources:

application: myapp
version: alpha-001
runtime: go
api_version: go1

handlers:
- url: /.*
  script: _go_app
  • Create a location for the Go source files.

% mkdir $HOME/myapp/go

  • Set your GOPATH to the location of your sources

% export GOPATH=$HOME/myapp/go

% goapp get github.com/golang/example/appengine-hello

This command will download the example app to the first path entry in the GOPATH

% go get -u golang.org/x/oauth2

% go get -u google.golang.org/cloud/storage

  • Attempt to run your go application

% goapp serve

You will see the following compilation error (no stack trace):

2015/12/23 10:37:07 go-app-builder: Failed parsing input: parser: bad import "syscall" in go/src/golang.org/x/net/ipv6/control_unix.go

答案1

得分: 2

这个错误是由以下两种情况之一引起的:

1)通过导入另一个使用syscall的包来隐式导入syscall,可以参考这个相关问题

2)将您的包源文件放在与您的项目的app.yaml文件位于相同级别或更低级别的GOPATH目录中(例如,在*~/go中有app.yaml*,并且包源文件在*~/go/gopath/src*中)。如果GOPATH中存在像x/net/internal/nettest这样的包,goapp在编译时将解析syscall导入并抛出编译错误。

避免这两种情况应足以防止任何bad import "syscall"错误或相关的编译错误。

英文:

This error is caused by either of two scenarios:

  1. Implicitly importing syscall by importing another package that uses it, as referenced in this related question.

  2. Having your package source files in your GOPATH located in a directory at or below the same level as your project's app.yaml (eg. app.yaml in ~/go, and packages sources in ~/go/gopath/src). If a package like x/net/internal/nettest exists in your GOPATH the syscall import will be parsed by goapp at compile time and throw the compilation error.

Avoiding these two scenarios should be sufficient to prevent any bad import "syscall" errors or related compilation errors.

答案2

得分: 0

重现了上述的初始步骤,并且得到了类似的错误,即使没有明确提到syscall。然而,在appengine-hello目录中运行“goapp serve”却没有任何错误。

Adam在第2点的解释在这里适用:需要将app.yaml文件放置在目录结构的正确级别上。

英文:

Reproduced the initial steps above and got a similar error, even if not explicitly mentioning syscall. However, running “goapp serve” in the appengine-hello directory results in no error at all.

Adam’s explanation at point 2 applies here correctly: one needs to place the app.yaml file at the right level in the directory structure.

答案3

得分: 0

sirupsen/logrus引用了syscall

它们指定了一个appengine标签,以便在AppEngine中使用,类似于go build -tags appengine,参考issue 310

然而,我还没有成功将其包含在一个AppEngine项目中,以便可以将此构建参数转发并在某个地方指定,以便它可以通过。如果我成功了,我会回来更新的。

英文:

sirupsen/logrus references syscall.

They have an appengine tag specified, not to include syscall so it's usable in AppEngine, something like go build -tags appengine as per issue 310.

However I haven't yet succeeded including it in an AppEngine project so that this build param could be forwarded and specified somewhere so that it goes through. I'll come back to update if I manage.

huangapple
  • 本文由 发表于 2015年12月8日 06:37:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/34144642.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定