how to import and use an external library into a go project

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

how to import and use an external library into a go project

问题

你好!根据你的描述,你想在Go语言项目中使用外部库。首先,你可以通过在终端中运行以下命令来获取aerospike客户端库:

go get github.com/aerospike/aerospike-client-go

这将下载并安装该库到你的Go语言环境中。然后,在你的代码中,你可以使用import语句将该库导入到你的解决方案中:

import "github.com/aerospike/aerospike-client-go"

这样你就可以在你的代码中使用该库提供的对象和功能了。希望这可以帮助到你!如果你还有其他问题,请随时提问。

英文:

I'm newbie to go lang and i created an hello project with intellij.

now I want to use external lib.
for example:

connect into aerospike using:

http://www.aerospike.com/docs/client/go/examples.html

what I don't understand is how to import it into solution.
I've run from the terminal the command:

go get github.com/aerospike/aerospike-client-go

but I don't see any result in the project and don't understand which object to use from my main method.

can you help?

答案1

得分: 7

go get命令会将依赖项下载到你的$GOPATH目录中,在构建源代码时,go编译器可以从该目录访问它。现在,你只需要通过完整的包名导入该包,例如import github.com/aerospike/aerospike-client-go

英文:

The go get command downloads the dependency to your $GOPATH dir from where it is accessible by the go compiler when building your sources. Now you simply have to import the package by its full name import github.com/aerospike/aerospike-client-go

huangapple
  • 本文由 发表于 2017年7月13日 21:37:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/45082322.html
匿名

发表评论

匿名网友

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

确定