LEADER 00000cam 2200361 i 4500 001 sky303526294 003 SKY 005 20210524144227.9 008 201028t20212021cc a 001 0 eng d 015 GBC106713|2bnb 020 9781492077213 020 1492077216 040 YDX|beng|erda|cYDX|dBDX|dUKMGB|dOCLCO|dOCLCF|dCDX|dOCLCO |dSKYRV|dUtOrBLW 082 04 005.13/3|223 092 004.6782|bGO 2021 100 1 Bodner, Jon,|eauthor. 245 10 Learning Go :|ban idiomatic approach to real-world Go programming /|cJon Bodner. 250 First edition. 264 1 Beijing ;|aBoston :|bO'Reilly,|c2021. 264 4 |c©2021 300 xvii, 352 pages :|billustrations ;|c24 cm 336 text|btxt|2rdacontent 337 unmediated|bn|2rdamedia 338 volume|bnc|2rdacarrier 500 Includes index. 505 00 |tPreface --|t1. Setting up your go environment ; |tInstalling the go tools ;|tThe go workspace ;|tThe go command ;|tgo run and go build ;|tGetting third-party go tools ;|tFormatting your code ;|tLinting and vetting ; |tChoose your tools ;|tVisual studio code ;|tGoLand ;|tThe go playground ;|tMakefiles ;|tStaying up to date ; |tWrapping up --|t2. Primitive types and declarations ; |tBuilt-in types ;|tThe zero value ;|tLiterals ;|tBooleans ;|tNumeric types ;|tA taste of strings and runes ; |tExplicit type conversion ;|tvar versus := ;|tUsing const ;|tTyped and untyped constants ;|tUnused variables ; |tNaming variables and constants ;|tWrapping up --|t3. Composite types ;|tArrays—Too rigid to use directly ; |tSlices ;|tlen ;|tappend ;|tCapacity ;|tmake ;|tDeclaring your slice ;|tSlicing slices ;|tConverting arrays to slices ;|tcopy ;|tStrings and runes and bytes ;|tMaps ; |tReading and writing a map ;|tThe comma ok idiom ; |tDeleting from maps ;|tUsing maps as sets ;|tStructs ; |tAnonymous structs ;|tComparing and converting structs ; |tWrapping up --|t4. Blocks, shadows, and control structures ;|tBlocks ;|tShadowing variables ;|tDetecting shadowed variables ;|tif ;|tfor, four ways ;|tThe complete for statement ;|tThe condition-only for statement ;|tThe infinite for statement ;|tbreak and continue ;|tThe for- range statement ;|tLabeling your for statements ; |tChoosing the right for statement ;|tswitch ;|tBlank switches ;|tChoosing between if and switch ;|tgoto—Yes, goto ;|tWrapping up --|t5. Functions ;|tDeclaring and calling functions ;|tSimulating named and optional parameters ;|tVariadic input parameters and slices ; |tMultiple return values ;|tMultiple return values are multiple values ;|tIgnoring returned values ;|tNamed return values ;|tBlank returns—never use these! ; |tFunctions are values ;|tFunction type declarations ; |tAnonymous functions ;|tClosures ;|tPassing functions as parameters ;|tReturning functions from functions ;|tdefer ;|tGo is call by value ;|tWrapping up --|t6. Pointers ;|tA quick pointer primer ;|tDon’t fear the pointers ; |tPointers indicate mutable parameters ;|tPointers are a last resort ;|tPointer passing performance ;|tThe zero value versus no value ;|tThe difference between maps and slices ;|tSlices as buffers ;|tReducing the garbage collector’s workload ;|tWrapping up --|t7. Types, methods, and interfaces ;|tTypes in go ;|tMethods ;|tPointer receivers and value receivers ;|tCode your methods for nil instances ;|tMethods are functions too ;|tFunctions versus methods ;|tType declarations aren’t inheritance ;|tTypes are executable documentation ;|tiota is for enumerations—sometimes ;|tUse embedding for composition ; |tEmbedding is not inheritance ;|tA quick lesson on interfaces ;|tInterfaces are type-safe duck typing ; |tEmbedding and interfaces ;|tAccept interfaces, return structs ;|tInterfaces and nil ;|tThe empty interface says nothing ;|tType assertions and type switches ;|tUse type assertions and type switches sparingly ;|tFunction types are a bridge to interfaces ;|tImplicit interfaces make dependency injection easier ;|tWire ;|tGo isn’t particularly object-oriented (and that’s great) ; |tWrapping up --|t8. Errors ;|tHow to handle errors: the basics ;|tUse strings for simple errors ;|tSentinel errors ;|tErrors are values ;|tWrapping errors ;|tIs and as ; |tWrapping errors with defer ;|tpanic and recover ; |tGetting a stack trace from an error ;|tWrapping up -- |t9. Modules, packages, and imports ;|tRepositories, modules, and packages ;|tgo.mod ;|tBuilding packages ; |tImports and exports ;|tCreating and accessing a package ;|tNaming packages ;|tHow to organize your module ; |tOverriding a package’s name ;|tPackage comments and godoc ;|tThe internal package ;|tThe init function: avoid if possible ;|tCircular dependencies ;|tGracefully renaming and reorganizing your api ;|tWorking with modules ;|tImporting third-party code ;|tWorking with versions ; |tMinimum version selection ;|tUpdating to compatible versions ;|tUpdating to incompatible versions ;|tVendoring ;|tpkg.go.dev ;|tAdditional information ;|tPublishing your module ;|tVersioning your module ;|tModule proxy servers ; |tSpecifying a proxy server ;|tPrivate repositories ; |tWrapping up --|t10. Concurrency in go ;|tWhen to use concurrency ;|tGoroutines ;|tChannels ;|tReading, writing, and buffering ;|tfor-range and channels ;|tClosing a channel ;|tHow channels behave ;|tselect ;|tConcurrency practices and patterns ;|tKeep your apis concurrency-free ;|tGoroutines, for loops, and varying variables ;|tAlways clean up your goroutines ;|tThe done channel pattern ; |tUsing a cancel function to terminate a goroutine ;|tWhen to use buffered and unbuffered channels ;|tBackpressure ; |tTurning off a case in a select ;|tHow to time out code ; |tUsing waitgroups ;|tRunning code exactly once ;|tPutting our concurrent tools together ;|tWhen to use mutexes instead of channels ;|tAtomics—You probably don’t need these ;|tWhere to learn more about concurrency ;|tWrapping up --|t11. The standard library ;|tio and friends ;|ttime ;|tMonotonic time ;|tTimers and timeouts ;|tencoding/json ;|tUse struct tags to add metadata ;|tUnmarshaling and marshaling ;|tJSON, readers, and writers ;|tEncoding and decoding JSON streams ;|tCustom JSON parsing ;|tnet/http ; |tThe client ;|tThe server ;|tWrapping up --|t12. The context ;|tWhat is the context? ;|tCancellation ;|tTimers ;|tHandling context cancellation in your own code ; |tValues ;|tWrapping up --|t13. Writing tests ;|tThe basics of testing ;|tReporting test failures ;|tSetting up and tearing down ;|tStoring sample test data ;|tCaching test results ;|tTesting your public api ;|tUse go-cmp to compare test results ;|tTable tests ;|tChecking your code coverage ;|tBenchmarks ;|tStubs in go ;|thttptest ; |tIntegration tests and build tags ;|tFinding concurrency problems with the race checker ;|tWrapping up --|t14. Here there be dragons: reflect, unsafe, and cgo ;|tReflection lets us work with types at runtime ;|tTypes, kinds, and values ;|tMaking new values ;|tUse reflection to check if an interface’s value is nil ;|tUse reflection to write a data marshaler ;|tBuild functions with reflection to automate repetitive tasks ;|tYou can build structs with reflection, but don’t ;|tReflection can’t make methods ; |tOnly use reflection if it’s worthwhile ;|tunsafe is unsafe ;|tUse unsafe to convert external binary data ; |tunsafe strings and slices ;|tunsafe tools ;|tCgo is for integration, not performance ;|tWrapping up --|t15. A look at the future: generics in go ;|tGenerics reduce repetitive code and increase type safety ;|tIntroducing generics in go ;|tUse type lists to specify operators ; |tGeneric functions abstract algorithms ;|tType lists limit constants and implementations ;|tThings that are left out ;|tIdiomatic go and generics ;|tFurther futures unlocked ;|tWrapping up. 520 Go is rapidly becoming the preferred language for building web services. While there are plenty of tutorials available that teach Go's syntax to developers with experience in other programming languages, tutorials aren't enough. They don't teach Go's idioms, so developers end up recreating patterns that don't make sense in a Go context. This practical guide provides the essential background you need to write clear and idiomatic Go. No matter your level of experience, you'll learn how to think like a Go developer. Author Jon Bodner introduces the design patterns experienced Go developers have adopted and explores the rationale for using them. You'll also get a preview of Go's upcoming generics support and how it fits into the language. Learn how to write idiomatic code in Go and design a Go project; Understand the reasons for the design decisions in Go; Set up a Go development environment for a solo developer or team; Learn how and when to use reflection, unsafe, and cgo; Discover how Go's features allow the language to run efficiently; Know which Go features you should use sparingly or not at all. 650 0 Go (Computer program language) 650 0 Computer programming. 650 0 Web applications|xProgramming. 650 0 Open source software.
|