Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between golang.org packages and the standard library

Tags:

go

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...
like image 918
Benjam Avatar asked Mar 17 '17 03:03

Benjam


2 Answers

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.

like image 69
elithrar Avatar answered Oct 20 '22 10:10

elithrar


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

like image 20
Flimzy Avatar answered Oct 20 '22 11:10

Flimzy