logo资料库

The.Go.Programming.Language.pdf

第1页 / 共400页
第2页 / 共400页
第3页 / 共400页
第4页 / 共400页
第5页 / 共400页
第6页 / 共400页
第7页 / 共400页
第8页 / 共400页
资料共400页,剩余部分请下载后查看
Table of Contents
Contents
Preface
The Origins of Go
The Go Project
Organization of the Book
Where to Find More Information
Acknowledgments
1. Tutorial
1.1. Hello, World
1.2. Command-Line Arguments
1.3. Finding Duplicate Lines
1.4. Animated GIFs
1.5. Fetching a URL
1.6. Fetching URLs Concurrently
1.7. A Web Server
1.8. Loose Ends
2. Program Structure
2.1. Names
2.2. Declarations
2.3. Variables
2.4. Assignments
2.5. Type Declarations
2.6. Packages and Files
2.7. Scope
3. Basic Data Types
3.1. Integers
3.2. Floating-Point Numbers
3.3. Complex Numbers
3.4. Booleans
3.5. Strings
3.6. Constants
4. Composite Types
4.1. Arrays
4.2. Slices
4.3. Maps
4.4. Structs
4.5. JSON
4.6. Text and HTML Templates
5. Functions
5.1. Function Declarations
5.2. Recursion
5.3. Multiple Return Values
5.4. Errors
5.5. Function Values
5.6. Anonymous Functions
5.7. Variadic Functions
5.8. Deferred Function Calls
5.9. Panic
5.10. Recover
6. Methods
6.1. Method Declarations
6.2. Methods with a Pointer Receiver
6.3. Composing Types by Struct Embedding
6.4. Method Values and Expressions
6.5. Example: Bit Vector Type
6.6. Encapsulation
7. Interfaces
7.1. Interfaces as Contracts
7.2. Interface Types
7.3. Interface Satisfaction
7.4. Parsing Flags with flag.Value
7.5. Interface Values
7.6. Sorting with sort.Interface
7.7. The http.Handler Interface
7.8. The error Interface
7.9. Example: Expression Evaluator
7.10. Type Assertions
7.11. Discriminating Errors with Type Assertions
7.12. Querying Behaviors with Interface Type Assertions
7.13. Type Switches
7.14. Example: Token-Based XML Decoding
7.15. A Few Words of Advice
8. Goroutines and Channels
8.1. Goroutines
8.2. Example: Concurrent Clock Server
8.3. Example: Concurrent Echo Server
8.4. Channels
8.5. Looping in Parallel
8.6. Example: Concurrent Web Crawler
8.7. Multiplexing with select
8.8. Example: Concurrent Directory Traversal
8.9. Cancellation
8.10. Example: Chat Server
9. Concurrency with Shared Variables
9.1. Race Conditions
9.2. Mutual Exclusion: sync.Mutex
9.3. Read/Write Mutexes: sync.RWMutex
9.4. Memory Synchronization
9.5. Lazy Initialization: sync.Once
9.6. The Race Detector
9.7. Example: Concurrent Non-Blocking Cache
9.8. Goroutines and Threads
10. Packages and the Go Tool
10.1. Inroduction
10.2. Import Paths
10.3. The Package Declaration
10.4. Import Declarations
10.5. Blank Imports
10.6. Packages and Naming
10.7. The Go Tool
11. Testing
11.1. The go test Tool
11.2. Test Functions
11.3. Coverage
11.4. Benchmark Functions
11.5. Profiling
11.6. Example Functions
12. Reflection
12.1. Why Reflections ?
12.2. reflect.Type and reflect.Value
12.3. Display, a Recursive Value Printer
12.4. Example: Encoding S-Expressions
12.5. Setting Variables with reflect.Value
12.6. Example: Decoding S-Expressions
12.7. Accessing Struct Field Tags
12.8. Displaying the Methods of a Type
12.9. A Word of Caution
13. Low-Level Programming
13.1. unsafe.Sizeof, Alignof, and Offsetof
13.2. unsafe.Pointer
13.3. Example: Deep Equivalence
13.4. Calling C Code with cgo
13.5. Another Word of Caution
Index
From the Library of YIGUANG HU
The Go Programming Language
This page intentionally left blank From the Library of YIGUANG HU
The Go Programming Language Alan A. A. Donovan Google Inc. Brian W. Kernighan Princeton University New York • Boston • Indianapolis • San Francisco Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City From the Library of YIGUANG HU
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trade- mark claim, the designations have been printed with initial capital letters or in all capitals. Th e authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, train- ing goals, marketing focus, or branding interests), please contact our corporate sales department at corpsales@pearsoned.com or (800) 382-3419. For government sales inquiries, please contact governmentsales@pearsoned.com. For questions about sales outside the United States, please contact international@pearsoned.com. Visit us on the Web: informit.com/aw Library of Congress Control Number: 2015950709 Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan All rights reserved. Printed in the United States of America. Th is publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, 200 Old Tappan Road, Old Tappan, New Jersey 07675, or you may fax your request to (201) 236-3290. Front cover: Millau Viaduct, Tarn valley, southern France. A paragon of simplicity in modern engi- neering design, the viaduct replaced a convoluted path from capital to coast with a direct route over the clouds. © Jean-Pierre Lescourret/Corbis. Back cover: the original Go gopher. © 2009 Renée French. Used under Creative Commons Attribu- tions 3.0 license. Typeset by the authors in Minion Pro, Lato, and Consolas, using Go, groff , ghostscript, and a host of other open-source Unix tools. Figures were created in Google Drawings. ISBN-13: 978-0-13-419044-0 ISBN-10: 0-13-419044-0 Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana. First printing, October 2015 From the Library of YIGUANG HU
Fo r Leil a an d Me g From the Library of YIGUANG HU
This page intentionally left blank From the Library of YIGUANG HU
Pr eface The Origins of Go The Go Pro jec t Organizat ion of the Book Wh ere to Find More Infor mat ion Ac knowledgments 1. Tutorial 1.1. Hel lo, Wor ld 1.2. Command-L ine Arguments 1.3. Finding Dup lic ate Lines 1.4. Animated GIFs 1.5. Fetching a URL 1.6. Fetching URLs Con cur rently 1.7. A We b Server 1.8. Loose End s 2. Pro gram Str ucture 2.1. Names 2.2. Declarat ions 2.3. Var iables 2.4. Assig nments 2.5. Typ e Decl arat ions 2.6. Packages and Files 2.7. Scope Cont ents xi xii xiii xv xvi xvii 1 1 4 8 13 15 17 19 23 27 27 28 30 36 39 41 45 vii From the Library of YIGUANG HU
分享到:
收藏