Go语言入门 第2版(影印版)
Go语言入门 第2版(影印版)
Jon Bodner
出版时间:2025年02月
页数:468
“Go是一种独特的语言,即使是经验丰富的程序员也需要‘忘记’一些东西,重新以不同的方式思考软件开发。这本书很好地展示了Go语言的重要特性,同时指出了惯用代码、陷阱以及设计模式。”
——Aaron Schlesinger
微软资深工程师

Go语言已经迅速成为构建Web服务的首选语言。尽管很多教程可以帮助有其他编程语言经验的开发人员学习Go的语法,但它们还是有所欠缺。这些教程没有教授Go的惯用法,导致开发人员经常重造不适合Go环境的模式。这本实用指南提供了编写清晰地道的Go代码所需的关键背景知识。
无论你的经验水平如何,你都将学会像Go开发人员那样思考。作者Jon Bodner介绍了老道的Go开发者采用的设计模式,探讨了这些模式背后的逻辑依据。本次更新版还加入了关于Go工具的新章节。
通过本书,你将学到:
● 编写地道的Go代码,设计Go项目
● 理解Go设计决策背后的缘由
● 设置个人开发者或团队的Go开发环境
● 何时以及如何使用反射、unsafe、cgo
● Go语言的特性如何使语言高效运行
● 哪些特性应当谨慎使用或完全避免使用
● 提高性能,优化内存使用,减少垃圾回收
● 如何使用Go的高级开发工具
  1. Preface
  2. 1. Setting Up Your Go Environment
  3. Installing the Go Tools
  4. Your First Go Program
  5. Choose Your Tools
  6. Makefiles
  7. The Go Compatibility Promise
  8. Staying Up-to-Date
  9. Exercises
  10. Wrapping Up
  11. 2. Predeclared Types and Declarations
  12. The Predeclared Types
  13. var Versus :=
  14. Using const
  15. Typed and Untyped Constants
  16. Unused Variables
  17. Naming Variables and Constants
  18. Exercises
  19. Wrapping Up
  20. 3. Composite Types
  21. Arrays—Too Rigid to Use Directly
  22. Slices
  23. Strings and Runes and Bytes
  24. Maps
  25. Structs
  26. Exercises
  27. Wrapping Up
  28. 4. Blocks, Shadows, and Control Structures
  29. Blocks
  30. Shadowing Variables
  31. if
  32. for, Four Ways
  33. switch
  34. goto—Yes, goto
  35. Exercises
  36. Wrapping Up
  37. 5. Functions
  38. Declaring and Calling Functions
  39. Functions Are Values
  40. Closures
  41. defer
  42. Go Is Call by Value
  43. Exercises
  44. Wrapping Up
  45. 6. Pointers
  46. A Quick Pointer Primer
  47. Don’t Fear the Pointers
  48. Pointers Indicate Mutable Parameters
  49. Pointers Are a Last Resort
  50. Pointer Passing Performance
  51. The Zero Value Versus No Value
  52. The Difference Between Maps and Slices
  53. Slices as Buffers
  54. Reducing the Garbage Collector’s Workload
  55. Tuning the Garbage Collector
  56. Exercises
  57. Wrapping Up
  58. 7. Types, Methods, and Interfaces
  59. Types in Go
  60. Methods
  61. iota Is for Enumerations—Sometimes
  62. Use Embedding for Composition
  63. Embedding Is Not Inheritance
  64. A Quick Lesson on Interfaces
  65. Interfaces Are Type-Safe Duck Typing
  66. Embedding and Interfaces
  67. Accept Interfaces, Return Structs
  68. Interfaces and nil
  69. Interfaces Are Comparable
  70. The Empty Interface Says Nothing
  71. Type Assertions and Type Switches
  72. Use Type Assertions and Type Switches Sparingly
  73. Function Types Are a Bridge to Interfaces
  74. Implicit Interfaces Make Dependency Injection Easier
  75. Wire
  76. Go Isn’t Particularly Object-Oriented (and That’s Great)
  77. Exercises
  78. Wrapping Up
  79. 8. Generics
  80. Generics Reduce Repetitive Code and Increase Type Safety
  81. Introducing Generics in Go
  82. Generic Functions Abstract Algorithms
  83. Generics and Interfaces 188
  84. Use Type Terms to Specify Operators
  85. Type Inference and Generics
  86. Type Elements Limit Constants
  87. Combining Generic Functions with Generic Data Structures
  88. More on comparable
  89. Things That Are Left Out
  90. Idiomatic Go and Generics
  91. Adding Generics to the Standard Library
  92. Future Features Unlocked
  93. Exercises
  94. Wrapping Up
  95. 9. Errors
  96. How to Handle Errors: The Basics
  97. Use Strings for Simple Errors
  98. Sentinel Errors
  99. Errors Are Values
  100. Wrapping Errors
  101. Wrapping Multiple Errors
  102. Is and As
  103. Wrapping Errors with defer
  104. panic and recover
  105. Getting a Stack Trace from an Error
  106. Exercises
  107. Wrapping Up
  108. 10. Modules, Packages, and Imports
  109. Repositories, Modules, and Packages
  110. Using go.mod
  111. Building Packages
  112. Working with Modules
  113. Publishing Your Module
  114. Versioning Your Module
  115. Module Proxy Servers
  116. Additional Details
  117. Exercises
  118. Wrapping Up
  119. 11. Go Tooling
  120. Using go run to Try Out Small Programs
  121. Adding Third-Party Tools with go install
  122. Improving Import Formatting with goimports
  123. Using Code-Quality Scanners
  124. Using govulncheck to Scan for Vulnerable Dependencies
  125. Embedding Content into Your Program
  126. Embedding Hidden Files
  127. Using go generate
  128. Working with go generate and Makefiles
  129. Reading the Build Info Inside a Go Binary
  130. Building Go Binaries for Other Platforms
  131. Using Build Tags
  132. Testing Versions of Go
  133. Using go help to Learn More About Go Tooling
  134. Exercises
  135. Wrapping Up
  136. 12. Concurrency in Go
  137. When to Use Concurrency
  138. Goroutines
  139. Channels
  140. select
  141. Concurrency Practices and Patterns
  142. When to Use Mutexes Instead of Channels
  143. Atomics—You Probably Don’t Need These
  144. Where to Learn More About Concurrency
  145. Exercises
  146. Wrapping Up
  147. 13. The Standard Library
  148. io and Friends
  149. time
  150. encoding/json
  151. net/http
  152. Structured Logging
  153. Exercises
  154. Wrapping Up
  155. 14. The Context
  156. What Is the Context?
  157. Values
  158. Cancellation
  159. Contexts with Deadlines
  160. Context Cancellation in Your Own Code
  161. Exercises
  162. Wrapping Up
  163. 15. Writing Tests
  164. Understanding the Basics of Testing
  165. Running Table Tests
  166. Running Tests Concurrently
  167. Checking Your Code Coverage
  168. Fuzzing
  169. Using Benchmarks
  170. Using Stubs in Go
  171. Using httptest
  172. Using Integration Tests and Build Tags
  173. Finding Concurrency Problems with the Data Race Detector
  174. Exercises
  175. Wrapping Up
  176. 16. Here Be Dragons: Reflect, Unsafe, and Cgo
  177. Reflection Lets You Work with Types at Runtime
  178. unsafe Is Unsafe
  179. Cgo Is for Integration, Not Performance
  180. Exercises
  181. Wrapping Up
  182. Index
书名:Go语言入门 第2版(影印版)
作者:Jon Bodner
国内出版社:东南大学出版社
出版时间:2025年02月
页数:468
书号:978-7-5766-1764-1
原版书书名:Learning Go, 2nd Edition
原版书出版商:O'Reilly Media
Jon Bodner
 
Jon Bodner拥有20多年的软件工程师、首席开发者和架构师工作经验。他从事过多个领域的软件开发工作,包括教育、金融、商业、医疗保健、法律、政府和互联网基础设施。
Jon是美国第一资本金融公司(Capital One)的杰出工程师,他为公司的开发和测试工作流做出了巨大贡献,开发了Web支付页面的检测与输入的专利技术,并合作开发了用于发现和管理软件开发问题的工具。
Jon 经常在Go会议上发表演讲,他关于Go和软件工程的博客文章已经有超过30万次的浏览量。他是Proteus数据访问库(https://github.com/jonbodner/proteus)的创建者,也是checks-out(LGTM项目的分支) (https://github.com/capitalone/checks-out)的联合开发者。
 
 
The animal on the cover of Learning Go is a plains pocket gopher (Geomys bursarius), a burrowing mammal found across the Great Plains of North America. These rodents are highly adapted to digging and live primarily underground.
Plains pocket gophers are covered in brown fur and have a nearly naked tail. Physical adaptations to digging include small eyes, short ears, and large, clawed front feet. They also have a tolerance for low oxygen and high carbon dioxide levels. The gophers are named for their external cheek pouches, which can be used for carrying food.
The gophers are territorial and aggressive, and will rarely enter another’s burrow.
They spend nearly three-quarters of their time in their own burrows, which contain their nests and food caches of roots and grasses. They go above ground to search for food and mates.
The plains pocket gopher’s conservation status is of least concern.
购买选项
定价:168.00元
书号:978-7-5766-1764-1
出版社:东南大学出版社