Go in Action. 2 Ed

Go in Action. 2 Ed

Go in Action. 2 Ed
Автор: Holmes Joel, Kennedy William, Walker Andy
Дата выхода: 2026
Издательство: Manning Publications Co.
Количество страниц: 374
Размер файла: 3,4 МБ
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы  Дополнительные материалы 

Go in Action, Second Edition MEAP V09....1

copyright....2

Welcome....3

brief contents....4

Chapter 1: Introducing Go....5

1.1 Solving modern programming challenges with Go....7

1.1.1 Development speed....7

1.1.2 Type Safety....9

1.1.3 Concurrency....10

1.1.4 Gos Type System....15

1.1.5 Garbage Collection....20

1.2 Summary....20

Chapter 2: Diving Into Go....22

2.1 Goal: A Program To Count Words....22

2.2 What You Need First....23

2.2.1 A Code Editor....23

2.2.2 Git....23

2.2.3 The Go Toolchain....24

2.2.4 Terminal Access....24

2.3 Creating Your Project Root....24

2.3.1 Initializing The Project Module....25

2.4 The First Iteration: Counting Spaces....26

2.4.1 Creating main.go....27

2.4.2 Building The Program With go build....27

2.4.3 Runing The Program With go run....28

2.4.4 Formatting Your Code With gofmt....28

2.4.5 Package Declarations....29

2.4.6 Import Declarations....30

2.4.7 Blocks and Scope....30

2.4.8 Variable Declaration....31

2.4.9 Comments....33

2.4.10 Basic For Loops....34

2.4.11 Calling Functions In Other Packages....35

2.5 A Better Way To Split The String....35

2.5.1 Introducing Package strings....36

2.5.2 Using go doc To View Package Documentation....36

2.5.3 Multiple Imports In An import Directive....37

2.5.4 Slices And len....38

2.6 Reading From A File....39

2.6.1 Using Package os To Interact With The Filesystem....39

2.6.2 Multiple Return Values....40

2.6.3 Basic Error Handling And The log Package....41

2.6.4 Counting The Words In The Loaded File....41

2.6.5 Running The Program On A File....42

2.7 Specifying The File....42

2.7.1 Getting Program Arguments From os.Args....43

2.7.2 Avoiding A Panic By Using len....44

2.7.3 Running Your Program With Arguments....45

2.8 A More Efficient Method....46

2.8.1 Using go doc To Learn More About Types....46

2.8.2 Files And io Interfaces....51

2.8.3 Integrating The Scanner Loop....52

2.8.4 Function Types For Modifying Behavior....54

2.9 Reading Multiple Files....55

2.10 Summary....58

Chapter 3: Primitive Types And Operators....60

3.1 Integer Types....61

3.1.1 Choosing An Integer Type....64

3.2 Floating-point Number Types....69

3.2.1 Special Floating-point Values....72

3.2.2 Choosing A Floating-point Type....73

3.3 Complex Number Types....74

3.4 Mathematical Operators....75

3.5 The bool Type....78

3.5.1 Boolean Functions....79

3.6 Struct Types....81

3.6.1 Structs As Types....83

3.7 Pointer Types....83

3.7.1 Dereferencing Pointers....85

3.7.2 Creating Pointers With new And Literals....86

3.8 The string Type....87

3.8.1 Interpreted Strings....87

3.8.2 Raw String Values....88

3.8.3 String Operations....88

3.8.4 len() And Unicode Characters....89

3.8.5 Iterating Unicode Strings Using A range Loop....91

3.8.6 The rune Type....91

3.8.7 Converting A string To A Slice Of rune....92

3.9 Summary....93

Chapter 4: Collection Types....94

4.1 Arrays....94

4.1.1 Declaring Arrays....95

4.1.2 Array Type And Length....98

4.1.3 Working Array Elements....99

4.1.4 Iterating Arrays With for....100

4.1.5 Arrays As Values....104

4.1.6 Multidimensional Arrays....106

4.1.7 Passing Arrays To Functions....109

4.1.8 The Problem With Arrays....110

4.2 Slices....110

4.2.1 Declaring Slices With Slice Literals....111

4.2.2 Declaring Slices With make....112

4.2.3 Nil Slices....114

4.2.4 Growing Slices With append....115

4.2.5 Avoiding Append Surprises....118

4.2.6 Slice Expressions....124

4.2.7 Copying Slices with copy....128

4.2.8 Avoiding Runtime Panics When Accessing Slice Values....130

4.2.9 Nil Slices Versus Empty Slices....134

4.3 Maps....136

4.3.1 Declaring Maps....139

4.3.2 Accessing Map Values....143

4.3.3 Removing Values From Maps.....146

4.3.4 Getting The Number Of Values In A Map....146

4.3.5 Iterating Maps....147

4.3.6 Passing Maps To Functions....148

4.3.7 Key And Value Types....149

4.4 Summary....150

Chapter 5: Working With Types....152

5.1 Modeling a Domain with Types....153

5.1.1 Named Types....154

5.1.2 Structs....156

5.2 Extending Types....158

5.2.1 Complex Types....160

5.3 Pointer Types....163

5.3.1 Methods and Behavior....165

5.4 Interfaces....168

5.5 Checking Types....172

5.5.1 Type Composition and Wrapping....174

5.5.2 Example: Putting It All Together....174

5.6 Summary....176

Chapter 6: Generics....177

6.1 Typed Parameters in Generics....178

6.1.1 Using Interface Constraints....182

6.1.2 Defining Custom Constraints....182

6.1.3 Leveraging Underlying Types with Tilde ()....183

6.1.4 Summary of Type Constraints....186

6.2 Implementing Generic Functions....186

6.3 Implementing Generic Interfaces....188

6.4 Multiple Type Parameters....197

6.5 Limitations and Considerations....203

6.5.1 Performance Considerations....203

6.5.2 Limitations of Go Generics....205

6.5.3 Common Gotchas....205

6.5.4 Backwards Compatibility....207

6.6 Standard Library support....208

6.6.1 The constraints Package....208

6.6.2 The slices and maps....209

6.6.3 The cmp Package....210

6.7 Just getting started....212

6.8 Summary....212

Chapter 7: Errors In Go....213

7.1 Go Errors Are Values....213

7.2 The Go Error Type....216

7.3 Generating New Errors....216

7.4 Handling Errors....219

7.5 Logging Errors....220

7.6 Annotating Error Logs With Formatting....221

7.7 Sentinel Errors....222

7.8 Identifying Different Types of Errors....225

7.9 Creating a custom error type....227

7.10 Getting The Underlying Error With errors.As....230

7.11 An Unexpected Error Journey....232

7.12 Dont Panic....234

7.12.1 Using Panic and Recover in your code....235

7.13 Summary....236

Chapter 8: Testing And Tooling....238

8.1 Test Files And Functions....239

8.2 Running Tests with go test....240

8.3 Test Functions....242

8.4 Test Lifecycle....244

8.4.1 Fatal And Non-Fatal Failures....245

8.5 Test Driven Design: A Calculator With A Twist....247

8.5.1 Black Box Testing....249

8.5.2 Writing Tests For Error Conditions....250

8.5.3 Writing Good Test Logs....252

8.5.4 Choosing Testing Targets....253

8.5.5 Table-Driven Testing....254

8.5.6 Implementation And Initial Testing....258

8.5.7 Code Coverage....260

8.6 Simulating Dependencies with an HTTP Server....265

8.7 Beyond Unit Tests....274

8.7.1 Benchmark Testing....274

8.7.2 Fuzz Testing....278

8.8 Summary....282

Chapter 9: Concurrency....284

9.1 When to use concurrency....285

9.2 Sync package....291

9.2.1 Wait Groups....291

9.2.2 Error Groups....294

9.2.3 Mutexes....296

9.3 Adding some Context....301

9.4 Channels....303

9.5 Concurrency Patterns....318

9.5.1 Workers....318

9.5.2 Fan out and Fan In....322

9.6 Helpful Concurrency Tips....329

9.6.1 Best Practices for Go Concurrency....329

9.6.2 When to Use Concurrency in Go....329

9.6.3 When Not to Use Concurrency in Go....330

9.7 Summary....331

Chapter 10: The Standard Library....332

10.1 fmt Package....333

10.2 flag Package....338

10.3 io Package....341

10.4 os Package....344

10.5 encoding Packages....354

10.5.1 JSON Processing....354

10.5.2 XML Processing....358

10.6 bufio Package....361

10.7 regexp Package....366

10.8 strings Package....369

10.9 strconv Package....370

10.9.1 Converting Numbers to Strings....372

10.10 Summary....374

Master Go language fundamentals, learn how to structure Go projects effectively, and deliver high-performance code using Go’s powerful concurrency model.

In Go in Action, Second Edition you will learn:


  • Go language fundamentals
  • How to set up and structure a Go software project
  • Working with the Go type system
  • Concurrency in Go
  • Go’s unique approach to error handling
  • Writing and capturing errors in your own software
  • How to use Go’s built-in testing and observability features

Go in Action, Second Edition has been fully updated to cover all the new features and idioms of the latest version of Go. In it, you’ll dive into Go's unique features and quickly get started writing real-world applications, such as websites and network servers.

About the technology

Designed by Google with productivity in mind, Go excels in modern, highly-dynamic environments. This modern language has all its concurrency primitives baked in, so Go users can handle problems like real-time performance with no additional tools required. Its simple-but-powerful type system includes generics and interfaces as first-class citizens. Best of all, because Go was designed to be simple, with a small number of keywords and an efficient standard library, it’s really easy to learn! In a cloud-first world, it’s easy to see why Go has quickly become a must-have skill.

About the book

Go in Action, Second Edition takes advantage of your existing programming knowledge to fast-track you to Go mastery. Google Developer Expert in Go Andrew Walker has revised the original bestseller with William Kennedy, covering new language features and adding compelling real-world case studies. You’ll get a jump start on Go’s syntax and internals as you build a comprehensive and idiomatic view of Go. Skip the absolute basics, and get straight to language implementation including Go's type system, concurrency, channels, and testing. Every example in the book comes complete with working code samples for you to download and tinker with.

About the reader

For programmers proficient in at least one OO programming language.


Похожее:

Список отзывов:

Нет отзывов к книге.