diff --git a/examples/json/json.go b/examples/json/json.go index ac9edad..7b10e0b 100644 --- a/examples/json/json.go +++ b/examples/json/json.go @@ -68,7 +68,7 @@ func main() { // Now let's look at decoding JSON data into Go // values. Here's an example for a generic data - // structure. + // structure. byt := []byte(`{"num":6.0,"strs":["a","b"]}`) // We need to provide a variable where the JSON diff --git a/examples/reading-files/reading-files.go b/examples/reading-files/reading-files.go index c6cbdaf..f07b186 100644 --- a/examples/reading-files/reading-files.go +++ b/examples/reading-files/reading-files.go @@ -69,7 +69,7 @@ func main() { // The `bufio` package implements a buffered // reader that may be useful both for its efficiency // with many small reads and because of the additional - // reading methods it provides. + // reading methods it provides. r4 := bufio.NewReader(f) b4, err := r4.Peek(5) check(err) diff --git a/examples/slices/slices.go b/examples/slices/slices.go index c44cca0..1918f98 100644 --- a/examples/slices/slices.go +++ b/examples/slices/slices.go @@ -27,7 +27,7 @@ func main() { // In addition to these basic operations, slices // support several more that make them richer than - // arrays. One is the builtin `append`, which + // arrays. One is the builtin `append`, which // returns a slice containing one or more new values. // Note that we need to accept a return value from // append as we may get a new slice value. diff --git a/examples/url-parsing/url-parsing.go b/examples/url-parsing/url-parsing.go index 1229bb8..991c6e9 100644 --- a/examples/url-parsing/url-parsing.go +++ b/examples/url-parsing/url-parsing.go @@ -9,7 +9,7 @@ import "strings" func main() { - // We'll parse this example URL, which includes a + // We'll parse this example URL, which includes a // scheme, authentication info, host, port, path, // query params, and query fragment. s := "postgres://user:pass@host.com:5432/path?k=v#f" diff --git a/public/arrays b/public/arrays index 2f24682..be2b767 100644 --- a/public/arrays +++ b/public/arrays @@ -20,6 +20,7 @@

Go by Example: Arrays

+ diff --git a/public/atomic-counters b/public/atomic-counters index 1102b1e..466792e 100644 --- a/public/atomic-counters +++ b/public/atomic-counters @@ -20,6 +20,7 @@

Go by Example: Atomic Counters

+
diff --git a/public/base64-encoding b/public/base64-encoding index 84b987a..e997ded 100644 --- a/public/base64-encoding +++ b/public/base64-encoding @@ -20,6 +20,7 @@

Go by Example: Base64 Encoding

+
diff --git a/public/channel-buffering b/public/channel-buffering index ee0e9b4..db69708 100644 --- a/public/channel-buffering +++ b/public/channel-buffering @@ -20,6 +20,7 @@

Go by Example: Channel Buffering

+
diff --git a/public/channel-directions b/public/channel-directions index 0c9831f..85b7891 100644 --- a/public/channel-directions +++ b/public/channel-directions @@ -20,6 +20,7 @@

Go by Example: Channel Directions

+
diff --git a/public/channel-synchronization b/public/channel-synchronization index 55f85b8..b45c984 100644 --- a/public/channel-synchronization +++ b/public/channel-synchronization @@ -20,6 +20,7 @@

Go by Example: Channel Synchronization

+
diff --git a/public/channels b/public/channels index 799189d..19d1dea 100644 --- a/public/channels +++ b/public/channels @@ -20,6 +20,7 @@

Go by Example: Channels

+
diff --git a/public/closing-channels b/public/closing-channels index 46544e6..f7f754b 100644 --- a/public/closing-channels +++ b/public/closing-channels @@ -20,6 +20,7 @@

Go by Example: Closing Channels

+
diff --git a/public/closures b/public/closures index e38208a..a61523b 100644 --- a/public/closures +++ b/public/closures @@ -20,6 +20,7 @@

Go by Example: Closures

+
diff --git a/public/collection-functions b/public/collection-functions index 0813854..805114d 100644 --- a/public/collection-functions +++ b/public/collection-functions @@ -20,6 +20,7 @@

Go by Example: Collection Functions

+
diff --git a/public/command-line-arguments b/public/command-line-arguments index 327c6d6..c54f7b8 100644 --- a/public/command-line-arguments +++ b/public/command-line-arguments @@ -20,6 +20,7 @@

Go by Example: Command-Line Arguments

+
diff --git a/public/command-line-flags b/public/command-line-flags index 8061b3c..216812d 100644 --- a/public/command-line-flags +++ b/public/command-line-flags @@ -20,6 +20,7 @@

Go by Example: Command-Line Flags

+
diff --git a/public/constants b/public/constants index 813eb93..e282270 100644 --- a/public/constants +++ b/public/constants @@ -20,6 +20,7 @@

Go by Example: Constants

+
diff --git a/public/defer b/public/defer index 4a978c7..0ae3203 100644 --- a/public/defer +++ b/public/defer @@ -20,6 +20,7 @@

Go by Example: Defer

+
diff --git a/public/environment-variables b/public/environment-variables index 5b86db8..1ee4f90 100644 --- a/public/environment-variables +++ b/public/environment-variables @@ -20,6 +20,7 @@

Go by Example: Environment Variables

+
diff --git a/public/epoch b/public/epoch index 1d372b3..9d57b2d 100644 --- a/public/epoch +++ b/public/epoch @@ -20,6 +20,7 @@

Go by Example: Epoch

+
diff --git a/public/errors b/public/errors index 913656c..385df4e 100644 --- a/public/errors +++ b/public/errors @@ -20,6 +20,7 @@

Go by Example: Errors

+
diff --git a/public/execing-processes b/public/execing-processes index 5e9eb34..ffd0a53 100644 --- a/public/execing-processes +++ b/public/execing-processes @@ -20,6 +20,7 @@

Go by Example: Exec'ing Processes

+
diff --git a/public/exit b/public/exit index a0bc797..30d016d 100644 --- a/public/exit +++ b/public/exit @@ -20,6 +20,7 @@

Go by Example: Exit

+
diff --git a/public/for b/public/for index 4d6c435..6f992d1 100644 --- a/public/for +++ b/public/for @@ -20,6 +20,7 @@

Go by Example: For

+
diff --git a/public/functions b/public/functions index 54c3651..b4b78fe 100644 --- a/public/functions +++ b/public/functions @@ -20,6 +20,7 @@

Go by Example: Functions

+
diff --git a/public/goroutines b/public/goroutines index 4fbedf2..523848f 100644 --- a/public/goroutines +++ b/public/goroutines @@ -20,6 +20,7 @@

Go by Example: Goroutines

+
diff --git a/public/hello-world b/public/hello-world index 88176eb..61300c0 100644 --- a/public/hello-world +++ b/public/hello-world @@ -20,6 +20,7 @@

Go by Example: Hello World

+
diff --git a/public/if-else b/public/if-else index 02c00c3..a60d49b 100644 --- a/public/if-else +++ b/public/if-else @@ -20,6 +20,7 @@

Go by Example: If/Else

+
diff --git a/public/interfaces b/public/interfaces index 24a40a7..7206a06 100644 --- a/public/interfaces +++ b/public/interfaces @@ -20,6 +20,7 @@

Go by Example: Interfaces

+
diff --git a/public/json b/public/json index 43bfa4d..95e5e28 100644 --- a/public/json +++ b/public/json @@ -20,6 +20,7 @@

Go by Example: JSON

+
diff --git a/public/line-filters b/public/line-filters index a8a00d8..7a8fd15 100644 --- a/public/line-filters +++ b/public/line-filters @@ -20,6 +20,7 @@

Go by Example: Line Filters

+
diff --git a/public/maps b/public/maps index e8d5d71..ca5c95a 100644 --- a/public/maps +++ b/public/maps @@ -20,6 +20,7 @@

Go by Example: Maps

+
diff --git a/public/methods b/public/methods index b618bc1..a2536a0 100644 --- a/public/methods +++ b/public/methods @@ -20,6 +20,7 @@

Go by Example: Methods

+
diff --git a/public/multiple-return-values b/public/multiple-return-values index 5de0a1f..65613e4 100644 --- a/public/multiple-return-values +++ b/public/multiple-return-values @@ -20,6 +20,7 @@

Go by Example: Multiple Return Values

+
diff --git a/public/mutexes b/public/mutexes index 8a076a7..c4d79dd 100644 --- a/public/mutexes +++ b/public/mutexes @@ -20,6 +20,7 @@

Go by Example: Mutexes

+
diff --git a/public/non-blocking-channel-operations b/public/non-blocking-channel-operations index 4e5e16c..3cebe83 100644 --- a/public/non-blocking-channel-operations +++ b/public/non-blocking-channel-operations @@ -20,6 +20,7 @@

Go by Example: Non-Blocking Channel Operations

+
diff --git a/public/number-parsing b/public/number-parsing index 6d92683..934e924 100644 --- a/public/number-parsing +++ b/public/number-parsing @@ -20,6 +20,7 @@

Go by Example: Number Parsing

+
diff --git a/public/panic b/public/panic index 95620aa..e7448cd 100644 --- a/public/panic +++ b/public/panic @@ -20,6 +20,7 @@

Go by Example: Panic

+
diff --git a/public/pointers b/public/pointers index 598dbfd..127bf24 100644 --- a/public/pointers +++ b/public/pointers @@ -20,6 +20,7 @@

Go by Example: Pointers

+
diff --git a/public/random-numbers b/public/random-numbers index 384a074..1ea1252 100644 --- a/public/random-numbers +++ b/public/random-numbers @@ -20,6 +20,7 @@

Go by Example: Random Numbers

+
diff --git a/public/range b/public/range index 36fb3c1..0096293 100644 --- a/public/range +++ b/public/range @@ -20,6 +20,7 @@

Go by Example: Range

+
diff --git a/public/range-over-channels b/public/range-over-channels index 0690cf4..d8507ad 100644 --- a/public/range-over-channels +++ b/public/range-over-channels @@ -20,6 +20,7 @@

Go by Example: Range over Channels

+
diff --git a/public/rate-limiting b/public/rate-limiting index cf5a9c6..f403da6 100644 --- a/public/rate-limiting +++ b/public/rate-limiting @@ -20,6 +20,7 @@

Go by Example: Rate Limiting

+
diff --git a/public/reading-files b/public/reading-files index 6517921..778f0a8 100644 --- a/public/reading-files +++ b/public/reading-files @@ -20,6 +20,7 @@

Go by Example: Reading Files

+
diff --git a/public/recursion b/public/recursion index df21191..c849ae4 100644 --- a/public/recursion +++ b/public/recursion @@ -20,6 +20,7 @@

Go by Example: Recursion

+
diff --git a/public/regular-expressions b/public/regular-expressions index 9d82695..522473f 100644 --- a/public/regular-expressions +++ b/public/regular-expressions @@ -20,6 +20,7 @@

Go by Example: Regular Expressions

+
diff --git a/public/select b/public/select index de44372..5edc2ae 100644 --- a/public/select +++ b/public/select @@ -20,6 +20,7 @@

Go by Example: Select

+
diff --git a/public/sha1-hashes b/public/sha1-hashes index 9a7d958..e08d2cd 100644 --- a/public/sha1-hashes +++ b/public/sha1-hashes @@ -20,6 +20,7 @@

Go by Example: SHA1 Hashes

+
diff --git a/public/signals b/public/signals index 6820a9c..29a4c64 100644 --- a/public/signals +++ b/public/signals @@ -20,6 +20,7 @@

Go by Example: Signals

+
diff --git a/public/slices b/public/slices index 1f39e96..1ac261d 100644 --- a/public/slices +++ b/public/slices @@ -20,6 +20,7 @@

Go by Example: Slices

+
diff --git a/public/sorting b/public/sorting index a8dc00d..ac16a99 100644 --- a/public/sorting +++ b/public/sorting @@ -20,6 +20,7 @@

Go by Example: Sorting

+
diff --git a/public/sorting-by-functions b/public/sorting-by-functions index 901cbce..f1b172b 100644 --- a/public/sorting-by-functions +++ b/public/sorting-by-functions @@ -20,6 +20,7 @@

Go by Example: Sorting by Functions

+
diff --git a/public/spawning-processes b/public/spawning-processes index 56e9ae1..1f42780 100644 --- a/public/spawning-processes +++ b/public/spawning-processes @@ -20,6 +20,7 @@

Go by Example: Spawning Processes

+
diff --git a/public/stateful-goroutines b/public/stateful-goroutines index e78f2d8..02ad6b7 100644 --- a/public/stateful-goroutines +++ b/public/stateful-goroutines @@ -20,6 +20,7 @@

Go by Example: Stateful Goroutines

+
diff --git a/public/string-formatting b/public/string-formatting index be4465d..d0823d6 100644 --- a/public/string-formatting +++ b/public/string-formatting @@ -20,6 +20,7 @@

Go by Example: String Formatting

+
diff --git a/public/string-functions b/public/string-functions index 9fb9bc7..07e70c1 100644 --- a/public/string-functions +++ b/public/string-functions @@ -20,6 +20,7 @@

Go by Example: String Functions

+
diff --git a/public/structs b/public/structs index 031d0ee..eab7abd 100644 --- a/public/structs +++ b/public/structs @@ -20,6 +20,7 @@

Go by Example: Structs

+
diff --git a/public/switch b/public/switch index 66cdc89..1e583ef 100644 --- a/public/switch +++ b/public/switch @@ -20,6 +20,7 @@

Go by Example: Switch

+
diff --git a/public/tickers b/public/tickers index 78abefb..e09ed05 100644 --- a/public/tickers +++ b/public/tickers @@ -20,6 +20,7 @@

Go by Example: Tickers

+
diff --git a/public/time b/public/time index 9b6c9f6..ea29d17 100644 --- a/public/time +++ b/public/time @@ -20,6 +20,7 @@

Go by Example: Time

+
diff --git a/public/time-formatting-parsing b/public/time-formatting-parsing index ae325c5..201e063 100644 --- a/public/time-formatting-parsing +++ b/public/time-formatting-parsing @@ -20,6 +20,7 @@

Go by Example: Time Formatting / Parsing

+
diff --git a/public/timeouts b/public/timeouts index 0a79faa..1547f58 100644 --- a/public/timeouts +++ b/public/timeouts @@ -20,6 +20,7 @@

Go by Example: Timeouts

+
diff --git a/public/timers b/public/timers index 2c1452a..c3726e5 100644 --- a/public/timers +++ b/public/timers @@ -20,6 +20,7 @@

Go by Example: Timers

+
diff --git a/public/url-parsing b/public/url-parsing index ed41e56..40b9d2e 100644 --- a/public/url-parsing +++ b/public/url-parsing @@ -20,6 +20,7 @@

Go by Example: URL Parsing

+
diff --git a/public/values b/public/values index 6f6c644..a77ef9f 100644 --- a/public/values +++ b/public/values @@ -20,6 +20,7 @@

Go by Example: Values

+
diff --git a/public/variables b/public/variables index 7c079ca..5db31b5 100644 --- a/public/variables +++ b/public/variables @@ -20,6 +20,7 @@

Go by Example: Variables

+
diff --git a/public/variadic-functions b/public/variadic-functions index c273143..793c97f 100644 --- a/public/variadic-functions +++ b/public/variadic-functions @@ -20,6 +20,7 @@

Go by Example: Variadic Functions

+
diff --git a/public/worker-pools b/public/worker-pools index 258a305..a13cb50 100644 --- a/public/worker-pools +++ b/public/worker-pools @@ -20,6 +20,7 @@

Go by Example: Worker Pools

+
diff --git a/public/writing-files b/public/writing-files index 3753007..8fbeb6b 100644 --- a/public/writing-files +++ b/public/writing-files @@ -20,6 +20,7 @@

Go by Example: Writing Files

+
diff --git a/tools/generate.go b/tools/generate.go index 1286bb5..fc1df7b 100644 --- a/tools/generate.go +++ b/tools/generate.go @@ -124,24 +124,24 @@ type Seg struct { } type Example struct { - Id, Name string - GoCode, GoCodeHash, UrlHash string - Segs [][]*Seg - NextExample *Example + Id, Name string + GoCode, GoCodeHash, UrlHash string + Segs [][]*Seg + NextExample *Example } func parseHashFile(sourcePath string) (string, string) { - var codehash,urlkey string + var codehash, urlkey string lines := readLines(sourcePath) - for idx,line := range lines { - switch idx { - case 0: - codehash = line - case 1: - urlkey = line - } + for idx, line := range lines { + switch idx { + case 0: + codehash = line + case 1: + urlkey = line + } } - return codehash,urlkey + return codehash, urlkey } func resetUrlHashFile(codehash, code, sourcePath string) string { @@ -153,8 +153,8 @@ func resetUrlHashFile(codehash, code, sourcePath string) string { defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) urlkey := string(body) - data := fmt.Sprintf("%s\n%s",codehash,urlkey) - ioutil.WriteFile(sourcePath,[]byte(data),0644) + data := fmt.Sprintf("%s\n%s", codehash, urlkey) + ioutil.WriteFile(sourcePath, []byte(data), 0644) return urlkey } @@ -203,25 +203,25 @@ func parseSegs(sourcePath string) ([]*Seg, string) { seg.CodeEmpty = (seg.Code == "") seg.CodeLeading = (i < (len(segs) - 1)) } - return segs,filecontent + return segs, filecontent } func parseAndRenderSegs(sourcePath string) ([]*Seg, string) { - segs,filecontent := parseSegs(sourcePath) + segs, filecontent := parseSegs(sourcePath) lexer := whichLexer(sourcePath) for _, seg := range segs { - if seg.Docs != "" { - seg.DocsRendered = markdown(seg.Docs) - } - if seg.Code != "" { - seg.CodeRendered = cachedPygmentize(lexer, seg.Code) - } + if seg.Docs != "" { + seg.DocsRendered = markdown(seg.Docs) + } + if seg.Code != "" { + seg.CodeRendered = cachedPygmentize(lexer, seg.Code) + } } // we are only interested in the 'go' code to pass to play.golang.org if lexer != "go" { - filecontent = "" - } - return segs,filecontent + filecontent = "" + } + return segs, filecontent } func parseExamples() []*Example { @@ -239,21 +239,21 @@ func parseExamples() []*Example { example.Segs = make([][]*Seg, 0) sourcePaths := mustGlob("examples/" + exampleId + "/*") for _, sourcePath := range sourcePaths { - switch strings.HasSuffix(sourcePath,".hash") { - case true: - example.GoCodeHash,example.UrlHash = parseHashFile(sourcePath) - default: - sourceSegs,filecontents := parseAndRenderSegs(sourcePath) - if (filecontents != "") { - example.GoCode = filecontents - } - example.Segs = append(example.Segs, sourceSegs) - } + switch strings.HasSuffix(sourcePath, ".hash") { + case true: + example.GoCodeHash, example.UrlHash = parseHashFile(sourcePath) + default: + sourceSegs, filecontents := parseAndRenderSegs(sourcePath) + if filecontents != "" { + example.GoCode = filecontents + } + example.Segs = append(example.Segs, sourceSegs) + } + } + newCodeHash := sha1Sum(example.GoCode) + if example.GoCodeHash != newCodeHash { + example.UrlHash = resetUrlHashFile(newCodeHash, example.GoCode, "examples/"+example.Id+"/"+example.Id+".hash") } - newCodeHash := sha1Sum(example.GoCode) - if (example.GoCodeHash != newCodeHash) { - example.UrlHash = resetUrlHashFile(newCodeHash,example.GoCode,"examples/"+example.Id+"/"+ example.Id + ".hash") - } examples = append(examples, &example) } }