diff --git a/meta/chapters.txt b/meta/chapters.txt index eb16424..26e2b6e 100644 --- a/meta/chapters.txt +++ b/meta/chapters.txt @@ -1,84 +1,84 @@ -hello-world -# values -# variables -# inline-assignment -# constants -# for -# if-else -# switch -# arrays -# slices -# maps -# range -# functions -# multiple-return-values -# varadic-functions -# closures -# recursion -# defer -# panic -# pointers -# new -# structs -# methods -# embedding -# interfaces -# errors -# ok-guards -# goroutines -# concurrent-goroutines -# channels -# channel-buffering -# channel-directions -# synchronization -# select -# timeouts -# scatter-gather -# rate-limiting -# worker-pools -# non-blocking-channel-operations -# closing-channels -timers -tickers -# state-goroutine -# state-mutex -sorting -sorting-by-functions -# collection-functions -# string-functions -# string-formatting -# regexs -# bytes -# json -# time -# epochs -# elapsed-time -# random-numbers -# number-parsing -# urls -# sha1-hashes -# base64-encoding -# reading-files -# writing-files -line-filters -# command-line-arguments -# command-line-flags -# environment-variables -# spawning-processes -# execing-processes -# signals -# exit -# http-client -# https-client -# redis -# postgres -# hello-web -# responses -# request-routing -# request-logging -# static-content -# basic-authentication -# canonical-hosts -# middleware -# graceful-shutdown -# https-servers +Hello World +# Values +# Variables +# Short Declarations +# Constants +# For +# If/Else +# Switch +# Arrays +# Slices +# Maps +# Range +# Functions +# Multiple Return Values +# Varadic Functions +# Closures +# Recursion +# Defer +# Panic +# Pointers +# New +# Structs +# Methods +# Embedding +# Interfaces +# Errors +# OK Guards +# Goroutines +# Concurrent Goroutines +# Channels +# Channel Buffering +# Channel Directions +# Synchronization +# Select +# Timeouts +# Scatter Gather +# Rate Limiting +# Worker Pools +# Non-Blocking Channel Operations +# Closing Channels +Timers +Tickers +# State Goroutine +# State Mutex +Sorting +Sorting by Functions +# Collection Functions +# String Functions +# String Formatting +# Regexs +# Bytes +# JSON +# Time +# Epochs +# Elapsed Time +# Random Numbers +# Number Parsing +# URLs +# SHA1 Hashes +# Base64 Encoding +# Reading Files +# Writing Files +Line Filters +# Command-Line Arguments +# Command-Line Flags +# Environment Variables +# Spawning Processes +# Execing Processes +# Signals +# Exit +# HTTP Client +# HTTPS Client +# Redis +# Postgres +# Hello Web +# Responses +# Request Routing +# Request Logging +# Static Content +# Basic Authentication +# Canonical Hosts +# Middleware +# Graceful Shutdown +# HTTPS Servers diff --git a/src/arrays/arrays.go b/src/arrays/arrays.go index 947db5f..3798840 100644 --- a/src/arrays/arrays.go +++ b/src/arrays/arrays.go @@ -1,5 +1,3 @@ -// ## Arrays - package main import "fmt" diff --git a/src/base64-encoding/base64-encoding.go b/src/base64-encoding/base64-encoding.go index 9fe52a2..e27a592 100644 --- a/src/base64-encoding/base64-encoding.go +++ b/src/base64-encoding/base64-encoding.go @@ -1,5 +1,3 @@ -// ## Base64 Encoding - package main import b64 "encoding/base64" diff --git a/src/basic-authentication/basic-authentication.go b/src/basic-authentication/basic-authentication.go index 36af865..efe193a 100644 --- a/src/basic-authentication/basic-authentication.go +++ b/src/basic-authentication/basic-authentication.go @@ -1,5 +1,3 @@ -// ## Basic Authentication - package main import ( diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go index c69baef..5460b24 100644 --- a/src/bytes/bytes.go +++ b/src/bytes/bytes.go @@ -1,5 +1,3 @@ -// ## Bytes - package main import "fmt" diff --git a/src/canonical-hosts/canonical-hosts.go b/src/canonical-hosts/canonical-hosts.go index 2a8b2a9..5a2574c 100644 --- a/src/canonical-hosts/canonical-hosts.go +++ b/src/canonical-hosts/canonical-hosts.go @@ -1,5 +1,3 @@ -// ## Canonical Hosts - package main import "net/http" diff --git a/src/channel-buffering/channel-buffering.go b/src/channel-buffering/channel-buffering.go index 98b774b..a4df028 100644 --- a/src/channel-buffering/channel-buffering.go +++ b/src/channel-buffering/channel-buffering.go @@ -1,5 +1,3 @@ -// ## Channel Buffering - package main import "fmt" diff --git a/src/channel-directions/channel-directions.go b/src/channel-directions/channel-directions.go index 6d336fa..d7092e2 100644 --- a/src/channel-directions/channel-directions.go +++ b/src/channel-directions/channel-directions.go @@ -1,5 +1,3 @@ -// ## Channel Directions - package main import "fmt" diff --git a/src/channels/channels.go b/src/channels/channels.go index 3af0cd0..589999f 100644 --- a/src/channels/channels.go +++ b/src/channels/channels.go @@ -1,5 +1,3 @@ -// ## Channels - package main import "fmt" diff --git a/src/closing-channels/closing-channels.go b/src/closing-channels/closing-channels.go index 5c8b629..1758887 100644 --- a/src/closing-channels/closing-channels.go +++ b/src/closing-channels/closing-channels.go @@ -1,5 +1,3 @@ -// ## Closing Channels - package main import "fmt" diff --git a/src/closures/closures.go b/src/closures/closures.go index a9766e6..8f2e90b 100644 --- a/src/closures/closures.go +++ b/src/closures/closures.go @@ -1,5 +1,3 @@ -// ## Closures - package main import "fmt" diff --git a/src/collection-functions/collection-functions.go b/src/collection-functions/collection-functions.go index cf308c0..636cba8 100644 --- a/src/collection-functions/collection-functions.go +++ b/src/collection-functions/collection-functions.go @@ -1,5 +1,3 @@ -// ## Collection Functions - package main import "strings" @@ -92,4 +90,4 @@ func main() { fmt.Println() } -// todo: generics +// todo: note no generics diff --git a/src/command-line-arguments/command-line-arguments.go b/src/command-line-arguments/command-line-arguments.go index aafef26..875fe9f 100644 --- a/src/command-line-arguments/command-line-arguments.go +++ b/src/command-line-arguments/command-line-arguments.go @@ -1,5 +1,3 @@ -// ## Command Line Arguments - // Use `os.Args` to access command-line arguments and // the name of the program. package main diff --git a/src/command-line-flags/command-line-flags.go b/src/command-line-flags/command-line-flags.go index 89b8b4e..b0a0249 100644 --- a/src/command-line-flags/command-line-flags.go +++ b/src/command-line-flags/command-line-flags.go @@ -1,5 +1,3 @@ -// ## Command Line Flags - package main import "flag" diff --git a/src/concurrent-goroutines/concurrent-goroutines.go b/src/concurrent-goroutines/concurrent-goroutines.go index 9efca37..493d7ba 100644 --- a/src/concurrent-goroutines/concurrent-goroutines.go +++ b/src/concurrent-goroutines/concurrent-goroutines.go @@ -1,5 +1,3 @@ -// ## Concurrent Goroutines - package main import "time" diff --git a/src/constants/constants.go b/src/constants/constants.go index cfc40e5..b5ae999 100644 --- a/src/constants/constants.go +++ b/src/constants/constants.go @@ -1,5 +1,3 @@ -// ## Constants - package main import "fmt" diff --git a/src/defer/defer.go b/src/defer/defer.go index 6a39377..d8fa3b8 100644 --- a/src/defer/defer.go +++ b/src/defer/defer.go @@ -1,5 +1,3 @@ -// ## Defer - package main import "fmt" diff --git a/src/elapsed-time/elapsed-time.go b/src/elapsed-time/elapsed-time.go index ae8026d..6e315ad 100644 --- a/src/elapsed-time/elapsed-time.go +++ b/src/elapsed-time/elapsed-time.go @@ -1,5 +1,3 @@ -// ## Elapsed Time - package main import "time" diff --git a/src/embedding/embedding.go b/src/embedding/embedding.go index 6992bf7..b43d8b1 100644 --- a/src/embedding/embedding.go +++ b/src/embedding/embedding.go @@ -1,5 +1,3 @@ -// ## Embedding - package main import "math" diff --git a/src/environment-variables/environment-variables.go b/src/environment-variables/environment-variables.go index e391596..af1b437 100644 --- a/src/environment-variables/environment-variables.go +++ b/src/environment-variables/environment-variables.go @@ -1,5 +1,3 @@ -// ## Environment Variables - package main // Use the `os` package to list, set, and get environment diff --git a/src/epochs/epochs.go b/src/epochs/epochs.go index a572b32..54d26b1 100644 --- a/src/epochs/epochs.go +++ b/src/epochs/epochs.go @@ -1,5 +1,3 @@ -// ## Epochs - // A common requirement in programms is getting the number // of seconds, milliseconds, or nanoseconds since the Unix // epoch. Here's how to do it in Go. diff --git a/src/errors/errors.go b/src/errors/errors.go index 7316902..273ac12 100644 --- a/src/errors/errors.go +++ b/src/errors/errors.go @@ -1,5 +1,3 @@ -// ## Errors - package main import ( diff --git a/src/execing-processes/execing-processes.go b/src/execing-processes/execing-processes.go index 625cef0..bac35ed 100644 --- a/src/execing-processes/execing-processes.go +++ b/src/execing-processes/execing-processes.go @@ -1,5 +1,3 @@ -// ## Exec'ing Processes - // In the previous chapter we looked at spawning external // process. We do this when we need the functionality // of another process accessable to a running Go process. diff --git a/src/exit/exit.go b/src/exit/exit.go index 19e070d..4d31f6f 100644 --- a/src/exit/exit.go +++ b/src/exit/exit.go @@ -1,5 +1,3 @@ -// ## Exit - // Use `os.Exit` to immediatly exit with a given // status. diff --git a/src/for/for.go b/src/for/for.go index 0bac477..8248240 100644 --- a/src/for/for.go +++ b/src/for/for.go @@ -1,5 +1,3 @@ -// ## For - // `for` is Go's only looping construct. Here are // two common forms. package main diff --git a/src/functions/functions.go b/src/functions/functions.go index cf8a2e6..c2bc7ca 100644 --- a/src/functions/functions.go +++ b/src/functions/functions.go @@ -1,5 +1,3 @@ -// ## Functions - // Funcations are critical in Go as in any other language. // We'll look at some basic examples first. diff --git a/src/goroutines/goroutines.go b/src/goroutines/goroutines.go index e23a905..e0bc17e 100644 --- a/src/goroutines/goroutines.go +++ b/src/goroutines/goroutines.go @@ -1,5 +1,3 @@ -// ## Goroutines - package main import "fmt" diff --git a/src/graceful-shutdown/graceful-shutdown.go b/src/graceful-shutdown/graceful-shutdown.go index 7aa344a..07feac2 100644 --- a/src/graceful-shutdown/graceful-shutdown.go +++ b/src/graceful-shutdown/graceful-shutdown.go @@ -1,5 +1,3 @@ -// ## Graceful Shutdown - package main import ( @@ -96,8 +94,5 @@ func main() { } } -// todo: clean up logging -// todo: limit shutdown time +// todo: pull in work from gobyexample-server // todo: factor out to cut-and-pastable against normal app -// todo: credit http://blog.nella.org/?p=879 -// todo: comment about tcp servers diff --git a/src/hello-web/hello-web.go b/src/hello-web/hello-web.go index a6b6819..0433f2c 100644 --- a/src/hello-web/hello-web.go +++ b/src/hello-web/hello-web.go @@ -1,5 +1,3 @@ -// ## Hello Web - package main import "net/http" diff --git a/src/hello-world/hello-world.go b/src/hello-world/hello-world.go index e5899a8..6a0bcd3 100644 --- a/src/hello-world/hello-world.go +++ b/src/hello-world/hello-world.go @@ -1,5 +1,3 @@ -// ## Hello World - // Our first program will print the classic "Hello world"` // message. Here's the full source code. package main diff --git a/src/http-client/http-client.go b/src/http-client/http-client.go index bca3223..fdcc352 100644 --- a/src/http-client/http-client.go +++ b/src/http-client/http-client.go @@ -1,5 +1,3 @@ -// ## HTTP Client - package main import "net/http" diff --git a/src/https-client/https-client.go b/src/https-client/https-client.go index 98dbdf2..23fa060 100644 --- a/src/https-client/https-client.go +++ b/src/https-client/https-client.go @@ -1,5 +1,3 @@ -// ## HTTPS Client - package main import "net/http" diff --git a/src/https-servers/https-servers.go b/src/https-servers/https-servers.go index f90264e..2820ae4 100644 --- a/src/https-servers/https-servers.go +++ b/src/https-servers/https-servers.go @@ -1,5 +1,3 @@ -// ## HTTPS Servers - package main import "net/http" diff --git a/src/if-else/if-else.go b/src/if-else/if-else.go index 835f18a..f843ed6 100644 --- a/src/if-else/if-else.go +++ b/src/if-else/if-else.go @@ -1,6 +1,5 @@ -// ## If/Else +// If/else in Go is straight-forward. -// If/else in go is straight-forward package main import "fmt" diff --git a/src/inline-assignment/inline-assignment.sh b/src/inline-assignment/inline-assignment.sh deleted file mode 100644 index 6d64c04..0000000 --- a/src/inline-assignment/inline-assignment.sh +++ /dev/null @@ -1,2 +0,0 @@ -$ go run inline-assignment.go -Hello assignment diff --git a/src/interfaces/interfaces.go b/src/interfaces/interfaces.go index 3702d28..340bcac 100644 --- a/src/interfaces/interfaces.go +++ b/src/interfaces/interfaces.go @@ -1,5 +1,3 @@ -// ## Interfaces - package main import "fmt" diff --git a/src/json/json.go b/src/json/json.go index d085067..4172f58 100644 --- a/src/json/json.go +++ b/src/json/json.go @@ -1,5 +1,3 @@ -// ## JSON - package main import "encoding/json" diff --git a/src/line-filters/line-filters.go b/src/line-filters/line-filters.go index 290a1e8..83762f6 100644 --- a/src/line-filters/line-filters.go +++ b/src/line-filters/line-filters.go @@ -1,5 +1,3 @@ -// ## Line Filters - // A _line filter_ is a common type of program that reads // input on stdin, processes it, and then prints some // derived result to stdout. `grep` and `sed` are common diff --git a/src/maps/maps.go b/src/maps/maps.go index 6ff889e..8f55959 100644 --- a/src/maps/maps.go +++ b/src/maps/maps.go @@ -1,5 +1,3 @@ -// ## Maps - // Maps are Go's built-in associative data type (sometimes // called "hashes" or "dicts" in other languages). diff --git a/src/methods/methods.go b/src/methods/methods.go index 8921124..4202249 100644 --- a/src/methods/methods.go +++ b/src/methods/methods.go @@ -1,5 +1,3 @@ -// ## Methods - package main import "fmt" diff --git a/src/middleware/middleware.go b/src/middleware/middleware.go index 99dbef2..55d88e4 100644 --- a/src/middleware/middleware.go +++ b/src/middleware/middleware.go @@ -1,5 +1,3 @@ -// ## Middleware - package main import "net/http" diff --git a/src/multiple-return-values/multiple-return-values.go b/src/multiple-return-values/multiple-return-values.go index 883decc..f8de302 100644 --- a/src/multiple-return-values/multiple-return-values.go +++ b/src/multiple-return-values/multiple-return-values.go @@ -1,5 +1,3 @@ -// ## Multiple Return Values - // Go has built-in support for multiple return values. // This feature is used often in idiomatic Go, for example // to return both result and error values from a function. diff --git a/src/new/new.go b/src/new/new.go index 59385bd..17fc924 100644 --- a/src/new/new.go +++ b/src/new/new.go @@ -1,5 +1,3 @@ -// ## New - package main import "fmt" diff --git a/src/non-blocking-channel-operations/non-blocking-channel-operations.go b/src/non-blocking-channel-operations/non-blocking-channel-operations.go index 21729cb..ad13299 100644 --- a/src/non-blocking-channel-operations/non-blocking-channel-operations.go +++ b/src/non-blocking-channel-operations/non-blocking-channel-operations.go @@ -1,5 +1,3 @@ -// ## Non-blocking Channel Operations - package main import "fmt" diff --git a/src/number-parsing/number-parsing.go b/src/number-parsing/number-parsing.go index 2a219bb..9c20c51 100644 --- a/src/number-parsing/number-parsing.go +++ b/src/number-parsing/number-parsing.go @@ -1,5 +1,3 @@ -// ## Number Parsing - package main // Package `strconv` provides the number parsing. diff --git a/src/ok-guards/ok-guards.go b/src/ok-guards/ok-guards.go index fc5e540..ab59e99 100644 --- a/src/ok-guards/ok-guards.go +++ b/src/ok-guards/ok-guards.go @@ -1,5 +1,3 @@ -// ## OK Guards - package main import "fmt" diff --git a/src/panic/panic.go b/src/panic/panic.go index 5b66167..82b79f3 100644 --- a/src/panic/panic.go +++ b/src/panic/panic.go @@ -1,5 +1,3 @@ -// ## Panic - // A `panic` means something went unexpectedly wrong. // Mostly we use it to fail fast on errors that // shouldn't occur during normal operation. diff --git a/src/pointers/pointers.go b/src/pointers/pointers.go index cb6fcad..302ec78 100644 --- a/src/pointers/pointers.go +++ b/src/pointers/pointers.go @@ -1,5 +1,3 @@ -// ## Pointers - package main import "fmt" diff --git a/src/postgres/postgres.go b/src/postgres/postgres.go index c69128c..37f2186 100644 --- a/src/postgres/postgres.go +++ b/src/postgres/postgres.go @@ -1,5 +1,3 @@ -// ## Postgres - package main import _ "github.com/bmizerany/pq" diff --git a/src/random-numbers/random-numbers.go b/src/random-numbers/random-numbers.go index 4b09b6c..fab3adb 100644 --- a/src/random-numbers/random-numbers.go +++ b/src/random-numbers/random-numbers.go @@ -1,5 +1,3 @@ -// ## Random Numbers - package main // The `math/rand` package provides psuedo-random diff --git a/src/range/range.go b/src/range/range.go index b84f771..56af522 100644 --- a/src/range/range.go +++ b/src/range/range.go @@ -1,5 +1,3 @@ -// ## Range - package main import "fmt" diff --git a/src/rate-limiting/rate-limiting.go b/src/rate-limiting/rate-limiting.go index 4f7a71c..9e6c42b 100644 --- a/src/rate-limiting/rate-limiting.go +++ b/src/rate-limiting/rate-limiting.go @@ -1,4 +1,3 @@ -// ## Rate Limiting package main import "time" diff --git a/src/reading-files/reading-files.go b/src/reading-files/reading-files.go index c713019..beedb6c 100644 --- a/src/reading-files/reading-files.go +++ b/src/reading-files/reading-files.go @@ -1,5 +1,3 @@ -// ## Reading files - package main import "io/ioutil" diff --git a/src/recursion/recursion.go b/src/recursion/recursion.go index b0a0993..322c071 100644 --- a/src/recursion/recursion.go +++ b/src/recursion/recursion.go @@ -1,5 +1,3 @@ -// ## Recursion - package main import "fmt" diff --git a/src/redis/redis.go b/src/redis/redis.go index 498bd51..33dc84a 100644 --- a/src/redis/redis.go +++ b/src/redis/redis.go @@ -1,5 +1,3 @@ -// ## Redis - package main import "github.com/fzzbt/radix/redis" diff --git a/src/regexs/regexs.go b/src/regexs/regexs.go index 5204f40..5394db3 100644 --- a/src/regexs/regexs.go +++ b/src/regexs/regexs.go @@ -1,5 +1,3 @@ -// ## Regexs - package main import "regexp" diff --git a/src/request-logging/request-logging.go b/src/request-logging/request-logging.go index c3ebc8a..f5a4d41 100644 --- a/src/request-logging/request-logging.go +++ b/src/request-logging/request-logging.go @@ -1,5 +1,3 @@ -// ## Request Logging - package main import "net/http" diff --git a/src/request-routing/request-routing.go b/src/request-routing/request-routing.go index 365bfe3..b1360ff 100644 --- a/src/request-routing/request-routing.go +++ b/src/request-routing/request-routing.go @@ -1,5 +1,3 @@ -// ## HTTP Server Routing - package main import "github.com/bmizerany/pat" diff --git a/src/responses/responses.go b/src/responses/responses.go index 458aeb1..1a4b52c 100644 --- a/src/responses/responses.go +++ b/src/responses/responses.go @@ -1,5 +1,3 @@ -// ## Responses - package main import "net/http" diff --git a/src/scatter-gather/scatter-gather.go b/src/scatter-gather/scatter-gather.go index af00b49..a486e43 100644 --- a/src/scatter-gather/scatter-gather.go +++ b/src/scatter-gather/scatter-gather.go @@ -1,5 +1,3 @@ -// ## Scatter-Gather - package main import "sync" diff --git a/src/select/select.go b/src/select/select.go index 0007a65..87c7c4e 100644 --- a/src/select/select.go +++ b/src/select/select.go @@ -1,5 +1,3 @@ -// ## Select - package main import "time" diff --git a/src/sha1-hashes/sha1-hashes.go b/src/sha1-hashes/sha1-hashes.go index 85a60cd..951119e 100644 --- a/src/sha1-hashes/sha1-hashes.go +++ b/src/sha1-hashes/sha1-hashes.go @@ -1,5 +1,3 @@ -// ## SHA1 Hashes - package main // Package `crypto/sha1` computes SHA1 hashes. diff --git a/src/inline-assignment/inline-assignment.go b/src/short-declarations/short-declarations.go similarity index 69% rename from src/inline-assignment/inline-assignment.go rename to src/short-declarations/short-declarations.go index 533d682..bdd1b81 100644 --- a/src/inline-assignment/inline-assignment.go +++ b/src/short-declarations/short-declarations.go @@ -1,11 +1,9 @@ -// ## Inline Assignment - package main import "fmt" func main() { // `x := val` is shorthand for `var x type = val`. - x := "Hello assignment" + x := "Hello var" fmt.Println(x) } diff --git a/src/short-declarations/short-declarations.sh b/src/short-declarations/short-declarations.sh new file mode 100644 index 0000000..0044451 --- /dev/null +++ b/src/short-declarations/short-declarations.sh @@ -0,0 +1,2 @@ +$ go run short-declarations.go +Hello var diff --git a/src/signals/signals.go b/src/signals/signals.go index b5d9dd6..04515b2 100644 --- a/src/signals/signals.go +++ b/src/signals/signals.go @@ -1,5 +1,3 @@ -// ## Signals - // Sometines we'd like our Go programs to intelligently // handle Unix signals. For example, we might want a // server to gracefully shutdown when it receives a diff --git a/src/slices/slices.go b/src/slices/slices.go index 6d9265c..fc0fb85 100644 --- a/src/slices/slices.go +++ b/src/slices/slices.go @@ -1,5 +1,3 @@ -// ## Slices - package main import "fmt" diff --git a/src/sorting-by-functions/sorting-by-functions.go b/src/sorting-by-functions/sorting-by-functions.go index 558ea62..19c24d9 100644 --- a/src/sorting-by-functions/sorting-by-functions.go +++ b/src/sorting-by-functions/sorting-by-functions.go @@ -1,5 +1,3 @@ -// ## Sorting by Functions - // Sometimes we'll want to sort a collection by something // other than its natural order. For example, suppose we // wanted to sort strings by their length instead of diff --git a/src/sorting/sorting.go b/src/sorting/sorting.go index 3b506be..7478806 100644 --- a/src/sorting/sorting.go +++ b/src/sorting/sorting.go @@ -1,5 +1,3 @@ -// ## Sorting - // Go's `sort` package implements sorting for builtins // and user-defined types. We'll look at sorting for // builtins first. diff --git a/src/spawning-processes/spawning-processes.go b/src/spawning-processes/spawning-processes.go index 0305c97..17aefc0 100644 --- a/src/spawning-processes/spawning-processes.go +++ b/src/spawning-processes/spawning-processes.go @@ -1,5 +1,3 @@ -// ## Spawning Processes - // Sometimes our Go programs need to spawn other, non-Go // processes. For example, the syntax highlighting in this // book is implementing by spawning a [`pygmentize`]() diff --git a/src/state-goroutine/state-goroutine.go b/src/state-goroutine/state-goroutine.go index 6eff8b4..3dfc7d8 100644 --- a/src/state-goroutine/state-goroutine.go +++ b/src/state-goroutine/state-goroutine.go @@ -1,5 +1,3 @@ -// ## State Goroutine - package main import "fmt" diff --git a/src/state-mutex/state-mutex.go b/src/state-mutex/state-mutex.go index a78271f..08e8b74 100644 --- a/src/state-mutex/state-mutex.go +++ b/src/state-mutex/state-mutex.go @@ -1,5 +1,3 @@ -// ## State Mutex - package main import "fmt" @@ -64,3 +62,5 @@ func main() { finalOpCount := atomic.LoadInt64(&opCount) fmt.Println(finalOpCount) } + +// todo: "State with Mutexes?" diff --git a/src/static-content/static-content.go b/src/static-content/static-content.go index c15056e..41b2d81 100644 --- a/src/static-content/static-content.go +++ b/src/static-content/static-content.go @@ -1,5 +1,3 @@ -// ## Static Content - package main import "net/http" diff --git a/src/string-formatting/string-formatting.go b/src/string-formatting/string-formatting.go index 080c5c5..da79a76 100644 --- a/src/string-formatting/string-formatting.go +++ b/src/string-formatting/string-formatting.go @@ -1,5 +1,3 @@ -// ## String Formatting - package main import "fmt" diff --git a/src/string-functions/string-functions.go b/src/string-functions/string-functions.go index 1eb8923..efa0bc6 100644 --- a/src/string-functions/string-functions.go +++ b/src/string-functions/string-functions.go @@ -1,5 +1,3 @@ -// ## String Functions - // The standard library's `strings` package provides many // useful string-related functions. diff --git a/src/structs/structs.go b/src/structs/structs.go index bd28bfb..c197e31 100644 --- a/src/structs/structs.go +++ b/src/structs/structs.go @@ -1,5 +1,3 @@ -// ## Structs - package main import "fmt" diff --git a/src/switch/switch.go b/src/switch/switch.go index 57105d7..11f0d32 100644 --- a/src/switch/switch.go +++ b/src/switch/switch.go @@ -1,5 +1,3 @@ -// ## Switch - // Switch statements allow... package main diff --git a/src/synchronization/synchronization.go b/src/synchronization/synchronization.go index c8abb1e..9190053 100644 --- a/src/synchronization/synchronization.go +++ b/src/synchronization/synchronization.go @@ -1,5 +1,3 @@ -// ## Synchronization - // We can use channels to synchronize execution // accross goroutines. Here's an example of waiting // for another goroutine to finish. diff --git a/src/tickers/tickers.go b/src/tickers/tickers.go index 6363531..fa10a6b 100644 --- a/src/tickers/tickers.go +++ b/src/tickers/tickers.go @@ -1,5 +1,3 @@ -// ## Tickers - // [Timers](timers) are for when you want to do // something once in the future - tickers are for when you // want to do something repeatedly at regular intervals. diff --git a/src/time/time.go b/src/time/time.go index ad52d34..973606a 100644 --- a/src/time/time.go +++ b/src/time/time.go @@ -1,5 +1,3 @@ -// ## Time - package main import "time" diff --git a/src/timeouts/timeouts.go b/src/timeouts/timeouts.go index 5733d32..fda81b9 100644 --- a/src/timeouts/timeouts.go +++ b/src/timeouts/timeouts.go @@ -1,5 +1,3 @@ -// ## Timeouts - package main import "time" diff --git a/src/timers/timers.go b/src/timers/timers.go index a1a030c..a0a8937 100644 --- a/src/timers/timers.go +++ b/src/timers/timers.go @@ -1,5 +1,3 @@ -// ## Timers - // We often want to execute Go code at some point in the // future, or repeatedly at some interval. Go's built-in // timer and ticker features make both of these tasks diff --git a/src/urls/urls.go b/src/urls/urls.go index f37b56f..cd5dfe2 100644 --- a/src/urls/urls.go +++ b/src/urls/urls.go @@ -1,5 +1,3 @@ -// ## URLs - package main import "fmt" diff --git a/src/values/values.go b/src/values/values.go index 57339cd..f7852ef 100644 --- a/src/values/values.go +++ b/src/values/values.go @@ -1,5 +1,3 @@ -// ## Values - // Go has various value types, including strings, // different types of numbers, booleans, etc. package main diff --git a/src/varadic-functions/varadic-functions.go b/src/varadic-functions/varadic-functions.go index e472abb..faf8dca 100644 --- a/src/varadic-functions/varadic-functions.go +++ b/src/varadic-functions/varadic-functions.go @@ -1,5 +1,3 @@ -// ## Varadic Functions - // Varadic functions can be called with any number of // trailing arguments. This is useful if you don't know // number of arguments that will be needed for a function diff --git a/src/variables/variables.go b/src/variables/variables.go index f684dea..934f111 100644 --- a/src/variables/variables.go +++ b/src/variables/variables.go @@ -1,5 +1,3 @@ -// ## Variables - package main import "fmt" diff --git a/src/worker-pools/worker-pools.go b/src/worker-pools/worker-pools.go index a76b6e5..396224e 100644 --- a/src/worker-pools/worker-pools.go +++ b/src/worker-pools/worker-pools.go @@ -1,5 +1,3 @@ -// ## Worker Pools - package main import "time" diff --git a/src/writing-files/writing-files.go b/src/writing-files/writing-files.go index 58ebd98..25d387d 100644 --- a/src/writing-files/writing-files.go +++ b/src/writing-files/writing-files.go @@ -1,11 +1,9 @@ -// ## Writing Files - package main import "os" func main() { - file, err := os.Create("xx-file-write.txt") + file, err := os.Create("writing-files.txt") if err != nil { panic(err) } diff --git a/template/chapter.tmpl b/template/chapter.tmpl index 8fc3fd8..bb35347 100644 --- a/template/chapter.tmpl +++ b/template/chapter.tmpl @@ -17,6 +17,7 @@
+

{{.Name}}

{{range .Segs}} diff --git a/tool/generate.go b/tool/generate.go index ec2b698..8b17274 100644 --- a/tool/generate.go +++ b/tool/generate.go @@ -130,7 +130,6 @@ type Chapter struct { func parseSegs(sourcePath string) []*Seg { lines := readLines(sourcePath) segs := []*Seg{} - segs = append(segs, &Seg{Code: "", Docs: ""}) lastSeen := "" for _, line := range lines { if line == "" { @@ -142,9 +141,8 @@ func parseSegs(sourcePath string) []*Seg { } matchDocs := docsPat.MatchString(line) matchCode := !matchDocs - lastSeg := segs[len(segs)-1] - newDocs := (lastSeen == "") || ((lastSeen != "docs") && (lastSeg.Docs != "")) - newCode := (lastSeen == "") || ((lastSeen != "code") && (lastSeg.Code != "")) + newDocs := (lastSeen == "") || ((lastSeen != "docs") && (segs[len(segs)-1].Docs != "")) + newCode := (lastSeen == "") || ((lastSeen != "code") && (segs[len(segs)-1].Code != "")) if newDocs || newCode { debug("NEWSEG") } @@ -154,7 +152,7 @@ func parseSegs(sourcePath string) []*Seg { newSeg := Seg{Docs: trimmed, Code: ""} segs = append(segs, &newSeg) } else { - lastSeg.Docs = lastSeg.Docs + "\n" + trimmed + segs[len(segs)-1].Docs = segs[len(segs)-1].Docs + "\n" + trimmed } debug("DOCS: " + line) lastSeen = "docs" @@ -163,7 +161,7 @@ func parseSegs(sourcePath string) []*Seg { newSeg := Seg{Docs: "", Code: line} segs = append(segs, &newSeg) } else { - lastSeg.Code = lastSeg.Code + "\n" + line + segs[len(segs)-1].Code = segs[len(segs)-1].Code + "\n" + line } debug("CODE: " + line) lastSeen = "code" @@ -187,15 +185,16 @@ func parseAndRenderSegs(sourcePath string) []*Seg { } func parseChapters() []*Chapter { - chapterLines := readLines("meta/chapters.txt") + chapterNames := readLines("meta/chapters.txt") chapters := make([]*Chapter, 0) - for _, chapterId := range chapterLines { - if (chapterId != "") && !strings.HasPrefix(chapterId, "#") { - chapter := Chapter{Id: chapterId} - chapterLines := readLines("src/" + chapterId + "/" + chapterId + ".go") - chapter.Name = chapterLines[0][6:] - chapterPath := "src/" + chapterId - sourcePaths := mustGlob(chapterPath + "/*") + for _, chapterName := range chapterNames { + if (chapterName != "") && !strings.HasPrefix(chapterName, "#") { + chapter := Chapter{Name: chapterName} + chapterId := strings.ToLower(chapterName) + chapterId = strings.Replace(chapterId, " ", "-", -1) + chapterId = strings.Replace(chapterId, "/", "-", -1) + chapter.Id = chapterId + sourcePaths := mustGlob("src/" + chapterId + "/*") segs := []*Seg{} for _, sourcePath := range sourcePaths { sourceSegs := parseAndRenderSegs(sourcePath)