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的设计不合理的地方之一。


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

查看所有标签

猜你喜欢:

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

Real-Time Rendering, Third Edition

Real-Time Rendering, Third Edition

Tomas Akenine-Moller、Eric Haines、Naty Hoffman / A K Peters/CRC Press / 2008-7-25 / USD 102.95

Thoroughly revised, this third edition focuses on modern techniques used to generate synthetic three-dimensional images in a fraction of a second. With the advent or programmable shaders, a wide varie......一起来看看 《Real-Time Rendering, Third Edition》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具