The go programming language 9780134190440, 0134190440

Go is an open-source programming language that makes it easy to build clean, reliable, and efficient software. It has be

2,143 278 6MB

English Pages XVII, 380 S.: graph. Darst [400] Year 2015;2016

Report DMCA / Copyright

DOWNLOAD FILE

The go programming language
 9780134190440, 0134190440

Table of contents :
Contents......Page 8
Preface......Page 12
The Origins of Go......Page 13
The Go Project......Page 14
Organization of the Book......Page 16
Where to Find More Information......Page 17
Acknowledgments......Page 18
1.1. Hello, World......Page 20
1.2. Command-Line Arguments......Page 23
1.3. Finding Duplicate Lines......Page 27
1.4. Animated GIFs......Page 32
1.5. Fetching a URL......Page 34
1.6. Fetching URLs Concurrently......Page 36
1.7. A Web Server......Page 38
1.8. Loose Ends......Page 42
2.1. Names......Page 46
2.2. Declarations......Page 47
2.3. Variables......Page 49
2.4. Assignments......Page 55
2.5. Type Declarations......Page 58
2.6. Packages and Files......Page 60
2.7. Scope......Page 64
3.1. Integers......Page 70
3.2. Floating-Point Numbers......Page 75
3.3. Complex Numbers......Page 80
3.4. Booleans......Page 82
3.5. Strings......Page 83
3.6. Constants......Page 94
4.1. Arrays......Page 100
4.2. Slices......Page 103
4.3. Maps......Page 112
4.4. Structs......Page 118
4.5. JSON......Page 126
4.6. Text and HTML Templates......Page 132
5.1. Function Declarations......Page 138
5.2. Recursion......Page 140
5.3. Multiple Return Values......Page 143
5.4. Errors......Page 146
5.5. Function Values......Page 151
5.6. Anonymous Functions......Page 154
5.7. Variadic Functions......Page 161
5.8. Deferred Function Calls......Page 162
5.9. Panic......Page 167
5.10. Recover......Page 170
6.1. Method Declarations......Page 174
6.2. Methods with a Pointer Receiver......Page 177
6.3. Composing Types by Struct Embedding......Page 180
6.4. Method Values and Expressions......Page 183
6.5. Example: Bit Vector Type......Page 184
6.6. Encapsulation......Page 187
7.1. Interfaces as Contracts......Page 190
7.2. Interface Types......Page 193
7.3. Interface Satisfaction......Page 194
7.4. Parsing Flags with flag. Value......Page 198
7.5. Interface Values......Page 200
7.6. Sorting with sort. Interface......Page 205
7.7. The http. Handler Interface......Page 210
7.8. The error Interface......Page 215
7.9. Example: Expression Evaluator......Page 216
7.10. Type Assertions......Page 224
7.11. Discriminating Errors with Type Assertions......Page 225
7.12. Querying Behaviors with Interface Type Assertions......Page 227
7.13. Type Switches......Page 229
7.14. Example: Token-Based XML Decoding......Page 232
7.15. A Few Words of Advice......Page 235
8.1. Goroutines......Page 236
8.2. Example: Concurrent Clock Server......Page 238
8.3. Example: Concurrent Echo Server......Page 241
8.4. Channels......Page 244
8.5. Looping in Paralle......Page 253
8.6. Example: Concurrent Web Crawler......Page 258
8.7. Multiplexing with select......Page 263
8.8. Example: Concurrent Directory Traversal......Page 266
8 9 Cancellation......Page 270
8.10. Example: Chat Server......Page 272
9.1. Race Conditions......Page 276
9.2. Mutual Exclusion: sync. Mutex......Page 281
9.3. Read/Write Mutexes: sync. RWMutex......Page 285
9.4. Memory Synchronization......Page 286
9.5. Lazy Initialization: sync.Once......Page 287
9.6. The Race Detector......Page 290
9.7. Example: Concurrent Non-Blocking Cache......Page 291
9.8. Goroutinesand Threads......Page 299
10.1. Introduction......Page 302
10.2. Import Paths......Page 303
10.4. Import Declarations......Page 304
10.5. Blank Imports......Page 305
10.6. Packages and Naming......Page 308
10.7. The Go Tool......Page 309
11. Testing......Page 320
11.2. Test Functions......Page 321
11.3. Coverage......Page 337
11.4. Benchmark Functions......Page 340
11.5. Profiling......Page 342
11.6. Example Functions......Page 345
12.1. Why Reflection?......Page 348
12.2. reflect. Type and reflect. Value......Page 349
12.3. Display, a Recursive Value Printer......Page 352
12.4. Example: Encoding S-Expressions......Page 357
12.5. Setting Variables with reflect.Value......Page 360
12.6. Example: Decoding S-Expressions......Page 363
12.7. Accessing Struct Field Tags......Page 367
12.8. Displaying the Methods of a Type......Page 370
12.9. A Word of Caution......Page 371
13. Low-Level Programming......Page 372
13.1. unsafe. Sizeof, Alignof,and Offsetof......Page 373
13.2. unsafe. Pointer......Page 375
13.3. Example: Deep Equivalence......Page 377
13.4. Calling C Code with cgo......Page 380
13.5. Another Word of Caution......Page 385
A......Page 386
C......Page 387
D......Page 388
E......Page 389
F......Page 390
H......Page 391
L......Page 392
M......Page 393
P......Page 394
R......Page 395
S......Page 396
T......Page 397
U......Page 398
Z......Page 399

Polecaj historie