如何设置特定的GOPATH?

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

How to set specific GOPATH?

问题

我已经安装了Ubuntu软件包中的Go。
基本库(fmt等)正常工作。

但是我在/var/www/mygoproject中有一个真实的项目,其中包含多个子文件夹,例如:

  • ./subfolder1
  • ./lib1
  • ./lib2
  • ./subfolder2

subfolderX包含不同的Go应用程序,libX包含共享代码。

我想在subfolderX中使用
import "lib1/package-inside"
但是我总是得到“imported and not used”错误。

我应该怎么做?

英文:

I have my go installed with ubuntu package.
Basics library (fmt etc.) are working correctly.

But I have a real project in /var/www/mygoproject with multiple subfolder ex:

  • ./subfolder1
  • ./lib1
  • ./lib2
  • ./subfolder2

subfolderX contain different go applications and libX contain shared code.

I would like, in subfolderX use
import "lib1/package-inside"
but I always get the imported and not used error.

What I have to do ?


edit:
code of /var/www/project/subproject/folder/alpha.go

package main

import (
	"subprojectA/folder/apackage" //doesnt work
    "./apackage" //works but not the cleanest
)

func main() {

	var sr interface{}
	sr = "tmp"

	apackage.Run(sr)
}

答案1

得分: 1

go build系统在第一次近似中通过在目录$GOPATH/src/pth中查找名为$(basename pth)的包来解析导入路径pth

我觉得你缺少了/src/部分。

关于GOPATH的有用讨论可以在这里找到(链接:http://golang.org/pkg/go/build/),另一个在这里(链接:http://golang.org/doc/code.html#tmp_3)。

英文:

The go build system, in the first approximation, resolves import path pth by looking for package named $(basename pth) in directory $GOPATH/src/pth.

It seems to me you're missing the /src/ part.

Useful discussion of GOPATH can be found eg. here, another here

huangapple
  • 本文由 发表于 2013年4月26日 23:48:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/16240417.html
匿名

发表评论

匿名网友

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

确定