How to include external file in Go?

2019-10-04 06:23发布

I'm using LiteIDE for Go. I have a Go file located here:

/Users/username/go/src/src/Helper/Helper.go

When I include the file using:

import "../Helper"

I get this error:

can't load package: /Users/username/go/src/src/projectA/main.go:4:8: local import "../Helper" in non-local package

Any ideas what I'm doing wrong?

标签: go package
1条回答
Evening l夕情丶
2楼-- · 2019-10-04 06:40

You import packages by import path. For package Helper, located in $GOPATH/src/Helper/, use:

import "Helper"

While they can work in some cases, relative paths aren't supported by the go toolchain, and are discouraged.

查看更多
登录 后发表回答