Go的custom import path

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

内容简介:什么是 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的设计不合理的地方之一。


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

查看所有标签

猜你喜欢:

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

HTML5和CSS3实例教程

HTML5和CSS3实例教程

Brian P.Hogan / 李杰、刘晓娜、柳靖、朱嵬 / 人民邮电出版社 / 2012-1 / 39.00元

《HTML5和CSS3实例教程》共分3部分,集中讨论了HTML5和CSS3规范及其技术的使用方法。首先是规范概述,介绍了新的结构化标签、表单域及其功能(包括自动聚焦功能和占位文本)和CSS3的新选择器。接下来是HTML对视频和音频的支持,讲述了画布上的图形绘制及CSS阴影、渐变和变换的使用方法。最后介绍使用HTML5的客户端特性(包括WebStorage、WebSQLDatabases以及离线支持......一起来看看 《HTML5和CSS3实例教程》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具