Go如何导入解析依赖项?

In Go, when I import a dependency like:

import "github.com/spf13/viper"

Which directories will Go look into, and in which order?

Lookup order:

  1. The vendor folder.
  2. The standard packages.
  3. GOPATH folder.

Run go help gopath to learn more on how Go search each directory.

A quick and easy way to see the search order and exact paths searched n a particular system is to run go build err.

This produces output similar to this:

can't load package: package err: cannot find package "err" in any of:
    C:\go\src\err (from $GOROOT)
    \\FREENAS\Global Documents\Projects\Go\src\err (from $GOPATH)