在我导入这个的场景中:
import (
"fmt"
"github.com/julienschmidt/httprouter"
"net/http"
"log"
)
但是 httprouter/router.go 导入:
import (
"net/http"
)
我还需要在我的 go 文件中导入“net/http”吗?
最佳答案
您的文件只需要关心在那个特定文件 中使用了哪些导入。
您可以尝试使用 goimports看看它如何建议要导入的东西。 Effective Go有这样的话:
When a package is imported, the package name becomes an accessor for the contents. After import "bytes" the importing package can talk about bytes.Buffer.
迂腐地说,这并不完全正确,因为您可以在同一个包中有多个文件,每个文件都需要导入它需要的任何内容(例如,一个包中的 2 个文件可能每个 import fmt
关于go - Go Lang 中的重复导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50863031/