gpt4 book ai didi

go - Go 中的内部包

转载 作者:IT王子 更新时间:2023-10-29 00:33:34 26 4
gpt4 key购买 nike

如何在 Go 中导入内部包?

import (

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

像这样不会出错:

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

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

最佳答案

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 建议的规则

如果导入代码位于以“internal”目录的父目录为根的树之外,则不允许导入包含元素“internal”的路径。

简答

你不能(至少很容易)也不应该。

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com