move h2 out of source files
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
// ## Arrays
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Base64 Encoding
|
||||
|
||||
package main
|
||||
|
||||
import b64 "encoding/base64"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Basic Authentication
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Bytes
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Canonical Hosts
|
||||
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Channel Buffering
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Channel Directions
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Channels
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Closing Channels
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Closures
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Collection Functions
|
||||
|
||||
package main
|
||||
|
||||
import "strings"
|
||||
@@ -92,4 +90,4 @@ func main() {
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
// todo: generics
|
||||
// todo: note no generics
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Command Line Arguments
|
||||
|
||||
// Use `os.Args` to access command-line arguments and
|
||||
// the name of the program.
|
||||
package main
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Command Line Flags
|
||||
|
||||
package main
|
||||
|
||||
import "flag"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Concurrent Goroutines
|
||||
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Constants
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Defer
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Elapsed Time
|
||||
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Embedding
|
||||
|
||||
package main
|
||||
|
||||
import "math"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Environment Variables
|
||||
|
||||
package main
|
||||
|
||||
// Use the `os` package to list, set, and get environment
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Errors
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Exit
|
||||
|
||||
// Use `os.Exit` to immediatly exit with a given
|
||||
// status.
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## For
|
||||
|
||||
// `for` is Go's only looping construct. Here are
|
||||
// two common forms.
|
||||
package main
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Functions
|
||||
|
||||
// Funcations are critical in Go as in any other language.
|
||||
// We'll look at some basic examples first.
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Goroutines
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Hello Web
|
||||
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Hello World
|
||||
|
||||
// Our first program will print the classic "Hello world"`
|
||||
// message. Here's the full source code.
|
||||
package main
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## HTTP Client
|
||||
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## HTTPS Client
|
||||
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## HTTPS Servers
|
||||
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// ## If/Else
|
||||
// If/else in Go is straight-forward.
|
||||
|
||||
// If/else in go is straight-forward
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
$ go run inline-assignment.go
|
||||
Hello assignment
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Interfaces
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## JSON
|
||||
|
||||
package main
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Maps
|
||||
|
||||
// Maps are Go's built-in associative data type (sometimes
|
||||
// called "hashes" or "dicts" in other languages).
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Methods
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Middleware
|
||||
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## New
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Non-blocking Channel Operations
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Number Parsing
|
||||
|
||||
package main
|
||||
|
||||
// Package `strconv` provides the number parsing.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## OK Guards
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Pointers
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Postgres
|
||||
|
||||
package main
|
||||
|
||||
import _ "github.com/bmizerany/pq"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Random Numbers
|
||||
|
||||
package main
|
||||
|
||||
// The `math/rand` package provides psuedo-random
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Range
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// ## Rate Limiting
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Reading files
|
||||
|
||||
package main
|
||||
|
||||
import "io/ioutil"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Recursion
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Redis
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/fzzbt/radix/redis"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Regexs
|
||||
|
||||
package main
|
||||
|
||||
import "regexp"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Request Logging
|
||||
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## HTTP Server Routing
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/bmizerany/pat"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Responses
|
||||
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Scatter-Gather
|
||||
|
||||
package main
|
||||
|
||||
import "sync"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Select
|
||||
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## SHA1 Hashes
|
||||
|
||||
package main
|
||||
|
||||
// Package `crypto/sha1` computes SHA1 hashes.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
2
src/short-declarations/short-declarations.sh
Normal file
2
src/short-declarations/short-declarations.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
$ go run short-declarations.go
|
||||
Hello var
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Slices
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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`]()
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## State Goroutine
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -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?"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Static Content
|
||||
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## String Formatting
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## String Functions
|
||||
|
||||
// The standard library's `strings` package provides many
|
||||
// useful string-related functions.
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Structs
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Switch
|
||||
|
||||
// Switch statements allow...
|
||||
|
||||
package main
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Time
|
||||
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Timeouts
|
||||
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## URLs
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Values
|
||||
|
||||
// Go has various value types, including strings,
|
||||
// different types of numbers, booleans, etc.
|
||||
package main
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Variables
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ## Worker Pools
|
||||
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user