Go的custom import path

栏目: Go · 发布时间: 6年前

内容简介:什么是 custom import path?就是例如第一行,就是 custom import path。因为目前

什么是 custom import path?就是 package 后面的注释,注释的内容是 // import xxxx 。这就是传说中的 custom import path。

例如 Docker 中的 代码

package daemon // import "github.com/docker/docker/daemon"

import (
    swarmtypes "github.com/docker/docker/api/types/swarm"
    "github.com/sirupsen/logrus"
)

// SetContainerConfigReferences sets the container config references needed
func (daemon *Daemon) SetContainerConfigReferences(name string, refs []*swarmtypes.ConfigReference) error {
    if !configsSupported() && len(refs) > 0 {
        logrus.Warn("configs are not supported on this platform")
        return nil
    }

    c, err := daemon.GetContainer(name)
    if err != nil {
        return err
    }
    c.ConfigReferences = append(c.ConfigReferences, refs...)
    return nil
}

第一行,就是 custom import path。因为目前 github.com/docker/docker 已经重命名为了 github.com/moby/moby 。所以如果 想愉快的补全代码或者是用IDE分析代码,正确的做法是,拷贝代码到本地,然后把 moby/moby 的路径改成 docker/docker

custom import path的出现就是为了防止仓库名发生改变之后,无法导入,然后制定的一种方案。好了,到了吐槽时间,这确实是属于 Go的设计不合理的地方之一。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Hard Thing About Hard Things

The Hard Thing About Hard Things

Ben Horowitz / HarperBusiness / 2014-3-4 / USD 29.99

Ben Horowitz, cofounder of Andreessen Horowitz and one of Silicon Valley's most respected and experienced entrepreneurs, offers essential advice on building and running a startup—practical wisdom for ......一起来看看 《The Hard Thing About Hard Things》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

MD5 加密
MD5 加密

MD5 加密工具