Benjam
Benjam

Reputation: 5326

Difference between golang.org packages and the standard library

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:

Upvotes: 9

Views: 2699

Answers (2)

elithrar
elithrar

Reputation: 24300

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.

Upvotes: 6

Jonathan Hall
Jonathan Hall

Reputation: 79734

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).

Upvotes: 6

Related Questions