书籍目录
Copyright
Preface
PART 1
WHY LEARN GO—GETTING STARTED
Chapter 1—Origins, Context and Popularity of Go
1.1 Origins and evolution
1.2 Main characteristics, context and reasons for developing a new language
1.2.1 Languages that influenced Go
1.2.2 Why a new language?
1.2.3 Targets of the language
1.2.4 Guiding design principles
1.2.5 Characteristics of the language
1.2.6 Uses of the language
1.2.7 Missing features?
1.2.8 Programming in Go
1.2.9 Summary
Chapter 2—Installation and Runtime Environment
2.1 Platforms and architectures
(1) The gc Go-compilers:
(2) The gccgo-compiler:
(3) File extensions and packages:
2.2 Go Environment variables
2.3 Installing Go on a Linux system
2.4 Installing Go on an OS X system
2.5 Installing Go on a Windows system
2.6 What is installed on your machine?
2.7 The Go runtime
2.8 A Go interpreter
Chapter 3—Editors, IDE’s and Other tools.
3.1 Basic requirements for a decent Go development environment
3.2 Editors and Integrated Development Environments
3.2.1. Golang LiteIDE
3.2.2. GoClipse
3.3 Debuggers
3.4 Building and running go-programs with command- and Makefiles
3.5 Formatting code: go fmt or gofmt
3.6 Documenting code: go doc or godoc
3.7 Other tools
3.8 Go’s performance
3.9 Interaction with other languages.
3.9.1. Interacting with C
3.9.2. Interacting with C++
PART 2
CORE CONSTRUCTS AND TECHNIQUES OF THE LANGUAGE
Chapter 4—Basic constructs and elementary data types
4.1. Filenames—Keywords—Identifiers
4.2. Basic structure and components of a Go-program
4.2.1 Packages, import and visibility
4.2.3 Comments
4.2.4 Types
4.2.5 General structure of a Go-program
4.2.6 Conversions
4.2.7 About naming things in Go
4.3. Constants
4.4. Variables
4.4.1 Introduction
4.4.2 Value types and reference types
4.4.3 Printing
4.4.4 Short form with the := assignment operator
4.4.5 Init-functions
4.5. Elementary types and operators
4.5.1. Boolean type bool
4.5.2. Numerical types
4.5.2.1 ints and floats
4.5.2.2 Complex numbers
4.5.2.3 Bit operators
4.5.2.4 Logical operators
4.5.2.5 Arithmetic operators
4.5.2.6 Random numbers
4.5.3. Operators and precedence
4.5.4. Aliasing types
4.5.5. Character type
4.6. Strings
4.7. The strings and strconv package
4.7.1—Prefixes and suffixes:
4.7.2—Testing whether a string contains a substring:
4.7.3—Indicating at which position (index) a substring or character occurs in a string:
4.7.4—Replacing a substring:
4.7.5—Counting occurrences of a substring:
4.7.6—Repeating a string:
4.7.7—Changing the case of a string:
4.7.8—Trimming a string:
4.7.9—Splitting a string:
4.7.10—Joining over a slice:
4.7.11—Reading from a string:
4.8. Times and dates
4.9. Pointers
Chapter 5—Control structures
5.1—The if else construct
5.2—Testing for errors on functions with multiple return values
5.3—The switch keyword
5.4—The for construct
5.4.1 Counter-controlled iteration
Character on position 2 is:
5.4.2 Condition-controlled iteration
5.4.3 Infinite loops
5.4.4 The for range construct
5.5—Break / continue
5.6—Use of labels with break and continue—goto
Chapter 6—Functions
6.1 Introduction
6.2 Parameters and return values
6.2.1 Call by value / Call by reference
6.2.2 Named return variables
6.2.3 Blank identifier
6.2.4 Changing an outside variable
6.3 Passing a variable number of parameters
6.4 Defer and tracing
6.5 Built-in functions
6.6 Recursive functions
6.8 Closures (function literals)
6.9 Applying closures: a function returning another function
6.10 Debugging with closures
6.11 Timing a function
6.12 Using memoization for performance
Chapter 7—Arrays and Slices
7.1 Declaration and initialization
7.1.1 Concept
7.1.2 Array literals
7.1.3 Multidimensional arrays
7.1.4 Passing an array to a function
7.2 Slices
7.2.1 Concept
7.2.2 Passing a slice to a function
7.2.3 Creating a slice with make()
7.2.4 Difference between new() and make()
7.2.5 Multidimensional slices
7.2.6 The bytes package
7.3 For range construct
7.4 Reslicing
7.5 Copying and appending slices
7.6 Applying strings, arrays and slices
7.6.1 Making a slice of bytes from a string
7.6.2 Making a substring of a string
7.6.3 Memory representation of a string and a slice
7.6.4 Changing a character in a string
7.6.5 Comparison function for byte arrays
7.6.6 Searching and sorting slices and arrays
7.6.7 Simulating operations with append
7.6.8 Slices and garbage collection
Chapter 8—Maps
8.1 Declaration, initialization and make
8.1.1 Concept
8.1.2 Map capacity
8.1.3 Slices as map values
8.2 Testing if a key-value item exists in a map—Deleting an element
8.3 The for range construct
8.4 A slice of maps
8.5 Sorting a map
8.6 Inverting a map
Chapter 9—Packages
A The standard library
9.1 Overview of the standard library.
9.2 The regexp package.
9.3 Locking and the sync package.
9.4 Accurate computations and the big package.
B Custom and external packages: use, build, test, document, install
9.5 Custom packages and visibility
9.6 Using godoc for your custom packages.
9.7 Using go install for installing custom packages.
9.8 Custom packages: map structure, go install and go test
9.8.1 Map-structure for custom packages
9.8.2 Locally installing the package
9.8.3 OS dependent code
9.9 Using git for distribution and installation.
9.9.1 Installing to github
9.9.2 Installing from github
9.10 Go external packages and projects.
9.11 Using an external library in a Go program.
Chapter 10—Structs and Methods
10.1 Definition of a struct
10.2 Creating a struct variable with a Factory method
10.2.1 A factory for structs
10.2.2 new() and make() revisited for maps and structs:
10.3 Custom package using structs
10.4 Structs with tags
10.5 Anonymous fields and embedded structs
10.5.1 Definition
10.5.2 Embedded structs
10.5.3 Conflicting names
10.6 Methods
10.6.1 What is a method?
10.6.2 Difference between a function and a method
10.6.3 Pointer or value as receiver
10.6.4 Methods and not-exported fields
10.6.5 Methods on embedded types and inheritance
10.6.6 How to embed functionality in a type
10.6.7 Multiple inheritance
10.6.8 Universal methods and method naming
10.6.9 Comparison between Go types and methods and other object-oriented languages.
10.7 The String()-method and format specifiers for a type
10.8 Garbage collection and SetFinalizer
Chapter 11—Interfaces and reflection
11.1 What is an interface?
11.2 Interface embedding interface(s)
11.3 How to detect and convert the type of an interface variable: type assertions
11.4 The type switch
11.5 Testing if a value implements an interface
11.6 Using method sets with interfaces
11.7 1st example: sorting with the Sorter interface
11.8 2nd example: Reading and Writing
11.9 Empty Interface
11.9.1 Concept
11.9.2 Constructing an array of a general type or with variables of different types
11.9.3 Copying a data-slice in a slice of interface{}
11.9.4 Node structures of general or different types
11.9.5 Interface to interface
11.10 The reflect package
11.10.1 Methods and types in reflect
11.10.2 Modifying (setting) a value through reflection
11.10.3 Reflection on structs
11.11 Printf and reflection.
11.12 Interfaces and dynamic typing
11.12.1 Dynamic typing in Go
11.12.2 Dynamic method invocation
11.12.3 Extraction of an interface
11.12.4 Explicitly indicating that a type implements an interface
11.12.5 Empty interface and function overloading
11.12.6 Inheritance of interfaces
11.13 Summary: the object-orientedness of Go
11.14 Structs, collections and higher order functions
PART 3
ADVANCED GO
Chapter 12—Reading and writing
12.1 Reading input from the user
12.2 Reading from and writing to a file
12.2.1 Reading from a file
12.2.2 The package compress: reading from a zipped file
12.2.3 Writing to a file
12.3 Copying files
12.4 Reading arguments from the command-line
12.4.1 With the os-package
12.4.2 With the flag-package
12.5 Reading files with a buffer
12.6 Reading and writing files with slices
12.7 Using defer to close a file
12.8 A practical example of the use of interfaces: fmt.Fprintf
12.9 The json dataformat
12.10 The xml dataformat
12.11 Datatransport through gob
12.12 Cryptography with go
Chapter 13—Error-handling and Testing
13.1 Error-handling
13.1.1 Defining errors
13.1.2 Making an error-object with fmt
13.2 Run-time exceptions and panic
13.4 Error-handling and panicking in a custom package
13.5 An error-handling scheme with closures
13.6 Starting an external command or program
13.7 Testing and benchmarking in Go
13.8 Testing: a concrete example
13.9 Using table-driven tests.
13.10 Investigating performance: tuning and profiling Go programs
13.10.1 Time and memory consumption
13.10.2 Tuning with go test
13.10.3 Tuning with pprof
Chapter 14—Goroutines and Channels
14.1 Concurrency, parallelism and goroutines
14.1.1 What are goroutines?
14.1.2 The difference between concurrency and parallelism
14.1.3 Using GOMAXPROCS
14.1.4 How to specify the number of cores to be used on the command-line?
14.1.5 Goroutines and coroutines
14.2 Channels for communication between goroutines
14.2.1 Concept
14.2.2 Communication operator <-
14.2.3 Blocking of channels
14.2.4 Goroutines synchronize through the exchange of data on one (or more) channel(s).
14.2.5 Asynchronous channels—making a channel with a buffer
14.2.6 Goroutine using a channel for outputting result(s)
14.2.7 Semaphore pattern
14.2.8 Implementing a parallel for-loop
14.2.9 Implementing a semaphore using a buffered channel
14.2.10 For—range applied to channels
14.2.11 Channel directionality
14.3 Synchronization of goroutines: closing a channel—testing for blocked channels
14.4 Switching between goroutines with select
14.5 Channels, Timeouts and Tickers
14.6 Using recover with goroutines
14.7 Comparing the old and the new model: Tasks and Worker processes.
14.8 Implementing a lazy generator
14.9 Implementing Futures
14.10 Multiplexing
14.10.1 A typical client-server pattern
14.10.2 Teardown: shutdown the server by signaling a channel
14.11 Limiting the number of requests processed concurrently
14.12 Chaining goroutines
14.13 Parallelizing a computation over a number of cores
14.14 Parallelizing a computation over a large amount of data
14.15 The leaky bucket algorithm
14.16 Benchmarking goroutines.
14.17 Concurrent acces to objects by using a channel.
Chapter 15—Networking, templating and web-applications
15.1 A tcp-server
15.2 A simple webserver
15.3 Polling websites and reading in a web page
15.4 Writing a simple web application
15.5 Making a web application robust
15.6 Writing a web application with templates
15.7 Exploring the template package
15.7.1. Field substitution: {{.FieldName}}
15.7.2. Validation of the templates
15.7.3 If-else
15.7.4 Dot and with-end
15.7.5 Template variables $
15.7.6 Range-end
15.7.7 Predefined template functions
15.8 An elaborated webserver with different functions
(works only on Unix because calls /bin/date)
15.9 Remote procedure calls with rpc
15.10 Channels over a network with netchan
15.11 Communication with websocket
15.12 Sending mails with smtp
PART 4
APPLYING GO
Chapter 16—Common Go Pitfalls or Mistakes
16.1 Hiding (shadowing) a variable by misusing short declaration.
16.2 Misusing strings.
16.3 Using defer for closing a file in the wrong scope.
16.4 Confusing new() and make()
16.5 No need to pass a pointer to a slice to a function
16.6 Using pointers to interface types
16.7 Misusing pointers with value types
16.8 Misusing goroutines and channels
16.9 Using closures with goroutines
16.10 Bad error handling
16.10.1 Don’t use booleans:
16.10.2 Don’t clutter your code with error-checking:
Chapter 17—Go Language Patterns
17.1 The comma, ok pattern
17.2 The defer pattern
17.3 The visibility pattern
17.4 The operator pattern and interface
17.4.1 Implement the operators as functions
17.4.2 Implement the operators as methods
17.4.3 Using an interface
Chapter 18—Useful Code Snippets—Performance Advice
18.1 Strings
18.2 Arrays and slices
18.3 Maps
18.4 Structs
18.5 Interfaces
18.6 Functions
18.7 Files
18.8 Goroutines and channels
18.9 Networking and web applications
18.9.1. Templating:
18.10 General
18.11 Performance best practices and advice
Chapter 19—Building a complete application
19.1 Introduction
19.2 Introducing Project UrlShortener
19.3 Data structure
19.4 Our user interface: a web server frontend
19.5 Persistent storage: gob
19.6 Using goroutines for performance
19.7 Using json for storage
19.8 Multiprocessing on many machines
19.9 Using a ProxyStore
19.10 Summary and enhancements
Chapter 20—Go in Google App Engine
20.1 What is Google App Engine ?
20.2 Go in the cloud
20.3 Installation of the Go App Engine SDK: the development environment for Go
20.3.1. Installation
20.3.2. Checking and testing
20.4 Building your own Hello world app
20.4.1 Map structure—Creating a simple http-handler
20.4.2 Creating the configuration file app.yaml
20.4.3 Iterative development
20.4.4. Integrating with the GoClipse IDE
20.5 Using the Users service and exploring its API
20.6 Handling forms
20.7 Using the datastore
20.8 Uploading to the cloud
Chapter 21—Real World Uses of Go
21.1 Heroku—a highly available consistent data store in Go.
21.2 MROffice—a VOIP system for call centers in Go.
21.3 Atlassian—a virtual machine cluster management system.
21.4 Camlistore—a content addressable storage system.
21.5 Other usages of the Go language.
APPENDICES
(A) CODE REFERENCE
(B) CUTE GO QUOTES.
GO QUOTES: TRUE BUT NOT SO CUTE.
(C) LIST OF CODE EXAMPLES (Listings)
(E) References in the text to Go—packages
(F) References in the text to Go—tools
(G) Answers to Questions
(H) ANSWERS TO EXERCISES
(I) BIBLIOGRAPHY (Resources and References)
Index
没有回复内容