OStack程序员社区-中国程序员成长平台

标题: go - Go 中的内部包 [打印本页]

作者: 菜鸟教程小白    时间: 2022-8-16 06:38
标题: go - Go 中的内部包

如何在 Go 中导入内部包?

import (

    "runtime/internal/atomic"
    "runtime/internal/sys"
)

像这样没有得到错误:

imports runtime/internal/atomic: use of internal package not allowed



并在主包中使用内部函数?



Best Answer-推荐答案


Background

Go encourages structuring a program as a collection of packages interacting using exported APIs. However, all packages can be imported. This creates a tension when implementing a library or command: it may grow large enough to structure as multiple packages, but splitting it would export the API used in those additional packages to the world. Being able to create packages with restricted visibility would eliminate this tension.


Go 1.4 提出的规则
如果导入代码位于以“内部”目录的父目录为根的树之外,则不允许导入包含元素“内部”的路径。
简答
你不能(至少很容易),你也不应该。

关于go - Go 中的内部包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41571946/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4