Skip to content
This repository has been archived by the owner on Jul 26, 2020. It is now read-only.

Latest commit

 

History

History
51 lines (42 loc) · 1.35 KB

go.org

File metadata and controls

51 lines (42 loc) · 1.35 KB

go

Table of Contents

error

fmt.Errorf("parsing %s as HTML: %v", url, err)

gopl book says:

Because error messages are frequently chained together, message strings should not be capitalized and newlines should be avoided.

log

log.Fatalf("Site is down: %v\n", err)

range

slice, kvs := []int{...}, map[string]string{...}
for _, num := range nums {}  // if idx not needed
for i, num := range nums {}
for k, v := range kvs {}
for k := range kvs {}        // just keys
for i, c := range "go" {}    // 'c' is 'rune' of the string

Documenting Packages

// Fprint formats using the default formats for its operands and writes to w.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func Fprint(w io.Writer, a ...interface{}) (n int, err error) {

gopl book says:

Go doc comments are always complete sentences, and the first sentence is usually a summary that starts with the name being declared.