Useful packages
The standard libary of Go includes a huge number of packages. It is veryenlightening to browse the $GOROOT/src
directory and look at thepackages. We cannot comment on each package, but the following are wortha mention: 11
fmt
Package
fmt
implements formatted I/O with functions analogousto C’sprintf
andscanf
. The format verbs are derivedfrom C’s but are simpler. Some verbs (%-sequences) that can be used:- %v, the value in a default format. when printing structs, the plus flag (%+v) adds field names.
- %#v, a Go-syntax representation of the value.
- %T, a Go-syntax representation of the type of the value.
io
This package provides basic interfaces to I/O primitives.Its primary job is to wrap existing implementations of such primitives,such as those in package os, into shared public interfaces thatabstract the functionality, plus some other related primitives.
bufio
This package implements buffered I/O. It wraps an
io.Reader
orio.Writer
object, creating another object (Reader or Writer) that also implementsthe interface but provides buffering and some help for textual I/O.sort
The
sort
package provides primitives for sorting arraysand user-defined collections.strconv
The
strconv
package implements conversions to and fromstring representations of basic data types.os
The
os
package provides a platform-independent interface to operatingsystem functionality. The design is Unix-like.sync
The package
sync
provides basic synchronization primitives such as mutualexclusion locks.flag
The
flag
package implements command-line flag parsing.encoding/json
The
encoding/json
package implements encoding and decoding of JSON objects asdefined in RFC 4627 [RFC4627].html/template
- Data-driven templates for generating textual output such as HTML.
Templates are executed by applying them to a data structure. Annotations inthe template refer to elements of the data structure (typically a field ofa struct or a key in a map) to control execution and derive values to bedisplayed. The template walks the structure as it executes and the “cursor”@ represents the value at the current location in the structure.
net/http
The
net/http
package implements parsing of HTTP requests, replies,and URLs and provides an extensible HTTP server and a basicHTTP client.unsafe
The
unsafe
package contains operations that step around the type safety of Go programs.Normally you don’t need this package, but it is worth mentioning that unsafe Go programsare possible.reflect
The
reflect
package implements run-time reflection, allowing a program tomanipulate objects with arbitrary types. The typical use is to take avalue with static typeinterface{}
and extract its dynamic typeinformation by callingTypeOf
, which returns an object with interfacetypeType
. See , Section .os/exec
- The
os/exec
package runs external commands.