From: Andrew Gerrand Date: Fri, 8 Jan 2016 01:06:45 +0000 (+1100) Subject: doc: add Overview and other small edits to How To Write Go Code X-Git-Tag: go1.6beta2~32 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1abb863d8341b17d7de725436a85198546a9fc01;p=gostls13.git doc: add Overview and other small edits to How To Write Go Code Fixes #9228 Change-Id: Ic4df4a39f6f363bdd6eb9228c8164e6e9dccee1b Reviewed-on: https://go-review.googlesource.com/5561 Reviewed-by: Rob Pike Reviewed-by: Austin Clements --- diff --git a/doc/code.html b/doc/code.html index 8cbfba04a0..fdca404ba4 100644 --- a/doc/code.html +++ b/doc/code.html @@ -24,21 +24,31 @@ A similar explanation is available as a

Code organization

-

Workspaces

+

Overview

+ +
    +
  • Go programmers typically keep all their Go code in a single workspace.
  • +
  • A workspace contains many version control repositories + (managed by Git, for example).
  • +
  • Each repository contains one or more packages.
  • +
  • Each package consists of one or more Go source files in a single directory.
  • +
  • The path to a package's directory determines its import path.
  • +

-The go tool is designed to work with open source code maintained -in public repositories. Although you don't need to publish your code, the model -for how the environment is set up works the same whether you do or not. +Note that this differs from other programming environments in which every +project has a separate workspace and workspaces are closely tied to version +control repositories.

+

Workspaces

+

-Go code must be kept inside a workspace. A workspace is a directory hierarchy with three directories at its root:

    -
  • src contains Go source files organized into packages (one package per directory), +
  • src contains Go source files,
  • pkg contains package objects, and
  • bin contains executable commands.
@@ -77,16 +87,25 @@ src/ stringutil/ reverse.go # package source reverse_test.go # test source + golang.org/x/image/ + .git/ # Git repository metadata + bmp/ + reader.go # package source + writer.go # package source + ... (many more repositories and packages omitted) ...

-This workspace contains one repository (example) -comprising two commands (hello and outyet) -and one library (stringutil). +The tree above shows a workspace containing two repositories +(example and image). +The example repository contains two commands (hello +and outyet) and one library (stringutil). +The image repository contains the bmp package +and several others.

-A typical workspace would contain many source repositories containing many +A typical workspace contains many source repositories containing many packages and commands. Most Go programmers keep all their Go source code and dependencies in a single workspace.

@@ -133,10 +152,16 @@ please see go help gopath

-

Package paths

+

Import paths

+ +

+An import path is a string that uniquely identifies a package. +A package's import path corresponds to its location inside a workspace +or in a remote repository (explained below). +

-The packages from the standard library are given short paths such as +The packages from the standard library are given short import paths such as "fmt" and "net/http". For your own packages, you must choose a base path that is unlikely to collide with future additions to the standard library or other external