如果包名称不能与导入路径的最后一个元素匹配的话,则必须使用导入别名
import (
"net/http"
client "example.com/client-go"
trace "example.com/trace/v2"
)
在所有其他场景中,应该避免导入别名,除非导入之间有直接冲突
Bad
import (
"fmt"
"os"
nettrace "golang.net/x/trace" //此处,应该避免使用导入别名
)
Good
import (
"fmt"
"os"
"runtime/trace"
nettrace "golang.net/x/trace" //有冲突了,需要使用导入别名
)
4540



被折叠的 条评论
为什么被折叠?



