Go example code

Clone this repo:

Branches

  1. 2e68773 all: gofmt by Russ Cox · 6 months ago master
  2. ad95e7f gotypes: add a link to the 1.18 API guide, and fix links by Robert Findley · 7 months ago
  3. 787a929 README.md: change the build instruction by Hana · 1 year, 2 months ago
  4. 09c3a5e README.md: update package paths to be golang.org/x/example/... by Hana · 1 year, 6 months ago
  5. bcf50bf go.mod/go.sum: add a go.mod and go.sum file for golang.org/x/example by Suzy Mueller · 1 year, 9 months ago

Go example projects

Go Reference

This repository contains a collection of Go programs and libraries that demonstrate the language, standard libraries, and tools.

Clone the project

$ git clone https://go.googlesource.com/example
$ cd example

https://go.googlesource.com/example is the canonical Git repository. It is mirrored at https://github.com/golang/example.

hello and stringutil

$ cd hello
$ go build

A trivial “Hello, world” program that uses a stringutil package.

Command hello covers:

  • The basic form of an executable command
  • Importing packages (from the standard library and the local repository)
  • Printing strings (fmt)

Library stringutil covers:

  • The basic form of a library
  • Conversion between string and []rune
  • Table-driven unit tests (testing)

outyet

$ cd outyet
$ go build

A web server that answers the question: “Is Go 1.x out yet?”

Topics covered:

  • Command-line flags (flag)
  • Web servers (net/http)
  • HTML Templates (html/template)
  • Logging (log)
  • Long-running background processes
  • Synchronizing data access between goroutines (sync)
  • Exporting server state for monitoring (expvar)
  • Unit and integration tests (testing)
  • Dependency injection
  • Time (time)

appengine-hello

A trivial “Hello, world” App Engine application intended to be used as the starting point for your own code. Please see Google App Engine SDK for Go and Quickstart for Go in the App Engine Standard Environment.

gotypes

The go/types package is a type-checker for Go programs. It is one of the most complex packages in Go's standard library, so we have provided this tutorial to help you find your bearings. It comes with several example programs that you can obtain using go get and play with as you learn to build tools that analyze or manipulate Go programs.

template

A trivial web server that demonstrates the use of the template package's block feature.