Go Programming

时间:2015-07-17 13:36:37
【文件属性】:
文件名称:Go Programming
文件大小:4.72MB
文件格式:PDF
更新时间:2015-07-17 13:36:37
go 编程 golang TABLE OF CONTENTS What is This Book About and Who is It For? ..................... 6 About the Author ................................................................. 8 1.1 Why a New Language? ............................................... 10 1.2 How Does Go Compare with C++? ............................ 10 1.2.1 Functions ............................................................. 11 1.2.2 Is Go Object Oriented like C++? ........................ 12 1.2.3 How do I free memory in Go? ............................ 14 1.2.4 Other stuff to be aware of .................................... 14 1.3 Summary ..................................................................... 16 2.1 What Platforms can I install Go on? ........................... 17 2.2 But what if I'm a Windows user? ............................... 18 2.2.1 Virtual Machine ................................................... 19 2.2.2 Dual Booting with Ubuntu ................................... 20 2.3 Installing Go ................................................................ 22 2.3.1 Environment Variables ........................................ 23 2.3.2 Installing Mercurial.. ............................................ 24 2.3.3 Fetching the Go Repository ................................. 27 2.3.4 Installing Go ......................................................... 27 2.4 Compiling, Linking, and Running .............................. 28 2.4.1 What About gccgo? .............................................. 29 2.5 Summary ..................................................................... 30 3.1 Standard 1/0 ................................................................ 33 3.1.1 The Obligatory "Hello World" ............................ 33 3.1.2 Retrieving Input from the User ............................ 35 3.2 File 1/0 ........................................................................ 38 3.2.1 Output to a File .................................................... 38 3.2.2 Input from a File .................................................. 43 3.2.3 A Short Summary of Permissions ........................ 47 3.3 Constants and Variables .............................................. 50 3.3.1 Identifiers ............................................................. 50 3.3.2 Constants .............................................................. 51 3.3.3 Variables .............................................................. 53 3.3.4 Time Savers : Short Declarations and Distributing .............. , ......................................................................... 55 3.4 Some Basic Data Types .............................................. 57 3.4.1 Numeric Data Types ............................................ 57 3.4.2 Character Data Type ............................................ 60 3.4.3 Boolean Data Type .............................................. 62 3.5 The String Data Type .................................................. 63 3.5.1 The strings Package ............................................. 65 Prefixes and Suffixes ................................................. 66 Counting Occurrences of a Substring ........................ 68 Index and Lastindex ................................................... 71 Repeat ........................................................................ 73 ToUpper and ToLower .............................................. 74 3.5 .2 The strconv Package ............................................ 7 6 3.6 Keywords and Operators ............................................. 78 3.6.1 Keywords ............................................................. 78 3.6.2 Operators .............................................................. 79 3.7 Summary ..................................................................... 80 4.1 Conditional Structures ................................................ 81 4.1.1 Basics of Logic .................................................... 82 Equality ...................................................................... 82 AND operator ............................................................. 82 OR operator ................................................................ 83 NOT operator ............................................................. 83 4.1.2 The if Structure .................................................... 83 4.1.3 The switch Structure ............................................ 87 4.2 Iteration ....................................................................... 92 4.3 break, continue, and Labels ........................................ 95 4.3.1 continue ................................................................ 95 4.3.2 break ..................................................................... 97 4.3.3 Labe1s ................................................................... 98 4.4 Functions ..................................................................... 99 4.4.1 Single Return Value ........................................... 1 00 4.4.2 Multiple Return Values .................................... 1 02 Result Parameters ..................................................... 1 05 Empty Return ........................................................... 1 05 4.4.3 The defer Keyword .......................................... 1 06 4.4.4 The Blank Identifier .......................................... 1 08 4.4.5 Example : Minimum I Maximum Function ....... 1 09 4.4 Summary ................................................................... 110 5.1 Pointers and References ............................................ 112 5.2 Arrays and Slices ...................................................... 114 5.2.1 Arrays ................................................................. 115 5.2.2 Slices .................................................................. 119 Basic Usage .............................................................. 120 Using make() to Create a Slice ................................ 122 Reslicing .................................................................. 123 5.3 Maps .......................................................................... 125 Testing for Existence of an Element. ....................... 128 Deleting an Element. ................................................ 128 5.4 Using range with for Loops ...................................... 130 5.5 Simulating Enumerated Types with iota ................... 133 5.6 Summary ................................................................... 134 6.1 Structured Types ....................................................... 136 6.1.1 Named Fields and Anonymous Fields ............... 136 6.1.2 Methods .............................................................. 140 6.2 Custom Packages and Visibility ............................... 143 6.2.1 Visibility ............................................................ 144 6.3 Interfaces ................................................................... 14 7 6.4 Summary ................................................................... 151 7.1 Concurrency .............................................................. 153 7 .1.1 Goroutines .......................................................... 153 7.2 Communication Channels ......................................... 156 7.2.1 The Communication Operator, <-...................... 157 7 .2.2 Communicability and Select Statements ........... 161 7.3 A Simple Client and Server ...................................... 163 7.4 Summary ................................................................... 169

网友评论