golang.org的包和标准库之间的区别是什么?

huangapple go评论89阅读模式
英文:

Difference between golang.org packages and the standard library

问题

我现在是你的中文翻译。以下是你要翻译的内容:

我最近开始使用Go语言,注意到在Go(标准库)和golang.org/x/之间存在重复的包。

我的问题是:为什么它们会发布两次?在这两个中,我应该使用哪一个(更更新、更规范等)?

到目前为止,我注意到一些重复发布的示例包括:

  • golang.org/x/net/htmlnet/html
  • golang.org/x/cryptocrypto
  • 还可能有其他我现在记不起来的...
英文:

I've been using go for a short time now, and I've been noticing that there are duplicate packages between Go (standard library) and golang.org/x/.

My questions are: Why are they released twice? And of the two, which one should I use (more up-to-date, canonical, etc)?

Some sample packages that are released twice that I've noticed so far:

  • golang.org/x/net/html vs net/html
  • golang.org/x/crypto vs crypto
  • and maybe more that I can't remember right now...

答案1

得分: 5

这些包是Go项目的一部分,但不属于主要的Go树。它们的开发比Go核心要求更宽松。

除非你有强烈的需求使用/x/变体并且可以接受破坏性变更的风险,否则请使用标准库的包。

英文:

https://golang.org/pkg/#subrepo

> These packages are part of the Go Project but outside the main Go tree.
> They are developed under looser compatibility requirements than the Go core.

Use the standard library packages unless you have a strong need to use the /x/ variant and can accept the risk of breaking changes.

答案2

得分: 5

golang.org/x/命名空间中的许多包以前只存在于那里,后来被纳入了标准库。为了向后兼容,golang.org/x/版本仍然存在。

然而,新的应用程序应该始终使用标准库版本,除非有充分的理由不这样做(比如使用仍然使用旧版本的库)。

英文:

Many of the packages in the golang.org/x/ namespace used to live only there, then were later adopted into the standard library. For backward compatibility, the golang.org/x/ version remains.

New apps should always use the standard library version, though, unless there's a compelling reason otherwise (such as using a library that still uses the old version).

huangapple
  • 本文由 发表于 2017年3月17日 11:22:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/42848636.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定