我该如何找到我的包? [英] How do I make go find my package?

查看:109
本文介绍了我该如何找到我的包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该在哪里放我的包,以便它可以被另一个包导入?

Where should I put my package so that it can be imported by another package?

$ tree
.
├── main.go
└── src
    └── test.go

1 directory, 2 files

$ cat src/test.go 
package test

$ cat main.go 
package main

import "test"

$ go build main.go 
main.go:3:8: import "test": cannot find package


推荐答案

设置你的GOPATH。将你的软件包源代码放入GOPATH / src / optional-whatever / foo / *。go并在代码中使用它作为

Set your GOPATH. Put your package foo source(s) in GOPATH/src/optional-whatever/foo/*.go and use it in code as

import "optional-whatever/foo"

不要需要明确安装foo,go工具是一个构建工具,它会在需要时为你自动完成。

You don't need to explicitly install foo, the go tool is a build tool, it will do that automagically for you whenever necessary.

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

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