Details

Go Programming Language For Dummies


Go Programming Language For Dummies


1. Aufl.

von: Wei-Meng Lee

22,99 €

Verlag: Wiley
Format: PDF
Veröffentl.: 29.03.2021
ISBN/EAN: 9781119786207
Sprache: englisch
Anzahl Seiten: 336

DRM-geschütztes eBook, Sie benötigen z.B. Adobe Digital Editions und eine Adobe ID zum Lesen.

Beschreibungen

<p><b>Ready, set, program with Go! </b></p> <p>Now is the perfect time to learn the Go Programming Language. It’s one of the most in-demand languages among tech recruiters and developers love its simplicity and power. <i>Go Programming Language For Dummies</i> is an easy way to add this top job skill to your toolkit. Written for novice and experienced coders alike, this book traverses basic syntax, writing functions, organizing data, building packages, and interfacing with APIs. </p> <p>Go—or GoLang, as it’s also known—has proven to be a strong choice for developers creating applications for the cloud-based world we live in. This book will put you on the path to using the language that’s created some of  today’s leading web applications, so you can steer your career where you want to Go! </p> <ul> <li>Learn how Go works and start writing programs and modules </li> <li>Install and implement the most powerful third-party Go packages </li> <li>Use Go in conjunction with web services and MySQL databases </li> <li>Keep your codebase organized and use Go to structure data </li> </ul> <p>With this book, you can join the growing numbers of developers using Go to create 21st century solutions. Step inside to take start writing code that puts data in users’ hands. </p>
<p><b>Introduction </b><b>1</b></p> <p>About This Book 1</p> <p>Foolish Assumptions 2</p> <p>Icons Used in This Book 2</p> <p>Beyond the Book 3</p> <p>Where to Go from Here 3</p> <p><b>Part 1: Getting Started with Go 5</b></p> <p><b>Chapter 1: Hello, Go!</b><b> 7</b></p> <p>Seeing What Learning Go Can Do for You 8</p> <p>Installing Go on Your Machine 9</p> <p>macOS 10</p> <p>Windows 11</p> <p>Using an Integrated Development Environment with Go 12</p> <p>Writing Your First Go Program 14</p> <p>Compiling and running the program 15</p> <p>Understanding how a Go program works 17</p> <p>Making sense of the Go file structure 18</p> <p>Compiling for multiple operating systems 19</p> <p>Comparing Go with Other Languages 21</p> <p>Syntax 21</p> <p>Compilation 22</p> <p>Concurrency 22</p> <p>Library support 22</p> <p><b>Chapter 2: Working with Different Data Types</b><b> 23</b></p> <p>Declaring Always-Changing Variables 24</p> <p>Using the var keyword: Type-inferred variables 24</p> <p>Specifying the data type: Explicitly typed variables 25</p> <p>Using the short variable declaration operator 26</p> <p>Declaring Never-Changing Constants 27</p> <p>Removing Unused Variables 27</p> <p>Dealing with Strings 29</p> <p>Performing Type Conversions 30</p> <p>Discovering the type of a variable 31</p> <p>Converting a variable’s type 32</p> <p>Interpolating strings 34</p> <p><b>Chapter 3: Making Decisions</b><b> 37</b></p> <p>Using If/Else Statements to Make Decisions 37</p> <p>Laying the foundation for the if/else statement: Logical and comparison operators 38</p> <p>Using the if/else statement 40</p> <p>Short-circuiting: Evaluating conditions in Go 42</p> <p>When You Have Too Many Conditions: Using the Switch Statement 46</p> <p>Switching with fall-throughs 47</p> <p>Matching multiple cases 48</p> <p>Switching without condition 48</p> <p><b>Chapter 4: Over and Over and Over: Using Loops</b><b> 51</b></p> <p>Performing Loops Using the for Statement 51</p> <p>Iterating over a Range of Values 56</p> <p>Iterating through arrays/slices 56</p> <p>Iterating through a string 58</p> <p>Using Labels with the for Loop 59</p> <p><b>Chapter 5: Grouping Code into Functions</b><b> 65</b></p> <p>Defining a Function 65</p> <p>Defining functions with parameters 66</p> <p>Defining functions with multiple parameters 68</p> <p>Passing arguments by value and by pointer 68</p> <p>Returning values from functions 71</p> <p>Naming return values 72</p> <p>Working with variadic functions 72</p> <p>Using Anonymous Functions 73</p> <p>Declaring an anonymous function 73</p> <p>Implementing closure using anonymous functions 74</p> <p>Implementing the filter() function using closure 76</p> <p><b>Part 2: Working with Data Structures 79</b></p> <p><b>Chapter 6: Slicing and Dicing Using Arrays and Slices</b><b> 81</b></p> <p>Arming Yourself to Use Arrays 81</p> <p>Declaring an array 82</p> <p>Initializing an array 83</p> <p>Working with multidimensional arrays 83</p> <p>Sleuthing Out the Secrets of Slices 86</p> <p>Creating an empty slice 86</p> <p>Creating and initializing a slice 88</p> <p>Appending to a slice 88</p> <p>Slicing and Ranging 92</p> <p>Extracting part of an array or slice 92</p> <p>Iterating through a slice 95</p> <p>Making copies of an array or slice 95</p> <p>Inserting an item into a slice 97</p> <p>Removing an item from a slice 99</p> <p><b>Chapter 7: Defining the Blueprints of Your Data Using Structs </b><b>101</b></p> <p>Defining Structs for a Collection of Items 101</p> <p>Creating a Go Struct 104</p> <p>Making a Copy of a Struct 105</p> <p>Defining Methods in Structs 107</p> <p>Comparing Structs 110</p> <p><b>Chapter 8: Establishing Relationships Using Maps</b><b> 113</b></p> <p>Creating Maps in Go 113</p> <p>Initializing a map with a map literal 115</p> <p>Checking the existence of a key 115</p> <p>Deleting a key 116</p> <p>Getting the number of items in a map 116</p> <p>Iterating over a map 117</p> <p>Getting all the keys in a map 117</p> <p>Setting the iteration order in a map 118</p> <p>Sorting the items in a map by values 118</p> <p>Using Structs and Maps in Go 121</p> <p>Creating a map of structs 121</p> <p>Sorting a map of structs 124</p> <p><b>Chapter 9: Encoding and Decoding Data Using JSON</b><b> 129</b></p> <p>Getting Acquainted with JSON 129</p> <p>Object 130</p> <p>String 130</p> <p>Boolean 131</p> <p>Number 131</p> <p>Object 132</p> <p>Array 132</p> <p>null 133</p> <p>Decoding JSON 134</p> <p>Decoding JSON to a struct 135</p> <p>Decoding JSON to arrays 136</p> <p>Decoding embedded objects 137</p> <p>Mapping custom attribute names 140</p> <p>Mapping unstructured data 141</p> <p>Encoding JSON 144</p> <p>Encoding structs to JSON 144</p> <p>Encoding interfaces to JSON 148</p> <p><b>Chapter 10: Defining Method Signatures Using Interfaces</b><b> 151</b></p> <p>Working with Interfaces in Go 152</p> <p>Defining an interface 152</p> <p>Implementing an interface 153</p> <p>Looking at How You May Use Interfaces 154</p> <p>Adding methods to a type that doesn’t satisfy an interface 158</p> <p>Using the Stringer interface 159</p> <p>Implementing multiple interfaces 160</p> <p>Using an empty interface 161</p> <p>Determining whether a value implements a specific interface 162</p> <p><b>Part 3: Multitasking in Go 163</b></p> <p><b>Chapter 11: Threading Using Goroutines</b><b> 165</b></p> <p>Understanding Goroutines 166</p> <p>Using Goroutines with Shared Resources 168</p> <p>Seeing how shared resources impact goroutines 168</p> <p>Accessing shared resources using mutual exclusion 171</p> <p>Using atomic counters for modifying shared resources 172</p> <p>Synchronizing Goroutines 174</p> <p><b>Chapter 12: Communicating between Goroutines Using Channels</b><b> 179</b></p> <p>Understanding Channels 179</p> <p>How channels work 180</p> <p>How channels are used 183</p> <p>Iterating through Channels 186</p> <p>Asynchronously Waiting on Channels 187</p> <p>Using Buffered Channels 192</p> <p><b>Part 4: Organizing Your Code 195</b></p> <p><b>Chapter 13: Using and Creating Packages in Go</b><b> 197</b></p> <p>Working with Packages 197</p> <p>Creating shareable packages 200</p> <p>Organizing packages using directories 202</p> <p>Using Third-Party Packages 204</p> <p>Emojis for Go 204</p> <p>Go Documentation 205</p> <p><b>Chapter 14: Grouping Packages into Modules</b><b> 211</b></p> <p>Creating a Module 211</p> <p>Testing and Building a Module 214</p> <p>Publishing a Module on GitHub 216</p> <p><b>Part 5: Seeing Go in Action 223</b></p> <p><b>Chapter 15: Consuming Web APIs Using Go</b><b> 225</b></p> <p>Understanding Web APIs 225</p> <p>Fetching Data from Web Services in Go 226</p> <p>Writing a Go program to connect to a web API 227</p> <p>Decoding JSON data 229</p> <p>Refactoring the code for decoding JSON data 233</p> <p>Fetching from multiple web services at the same time 238</p> <p>Returning Goroutine’s results to the main() function 239</p> <p><b>Chapter 16: Getting Ready to Serve Using REST APIs</b><b> 243</b></p> <p>Building Web Services Using REST APIs 243</p> <p>HTTP messages 244</p> <p>REST URLs 244</p> <p>REST methods 246</p> <p>REST response 248</p> <p>Creating a REST API in Go 249</p> <p>Getting your REST API up and running 249</p> <p>Testing the REST API 251</p> <p>Registering additional paths 251</p> <p>Passing in query string 254</p> <p>Specifying request methods 255</p> <p>Storing the course information on the REST API 257</p> <p>Testing the REST API again 267</p> <p><b>Chapter 17: Working with Databases</b><b> 271</b></p> <p>Setting Up a MySQL Database Server 272</p> <p>Interfacing with the MySQL server 272</p> <p>Creating a database and table 274</p> <p>Creating a new account and granting permission 275</p> <p>Connecting to the MySQL Database in Go 276</p> <p>Retrieving a record 278</p> <p>Adding a record 280</p> <p>Modifying a record 281</p> <p>Deleting a record 283</p> <p><b>Part 6: The Part of Tens 285</b></p> <p><b>Chapter 18: Ten Useful Go Packages to Create Applications</b><b> 287</b></p> <p>color 287</p> <p>Installation 288</p> <p>Code sample 288</p> <p>now 288</p> <p>Installation 288</p> <p>Code sample 288</p> <p>go-pushbullet 289</p> <p>Installation 289</p> <p>Code sample 289</p> <p>goid 290</p> <p>Installation 290</p> <p>Code sample 290</p> <p>json2go 291</p> <p>Installation 291</p> <p>Code sample 291</p> <p>gojq 292</p> <p>Installation 293</p> <p>Code sample 293</p> <p>turtle 294</p> <p>Installation 294</p> <p>Code sample 294</p> <p>go-http-client 295</p> <p>Installation 295</p> <p>Code sample 295</p> <p>notify 296</p> <p>Installation 296</p> <p>Code sample 296</p> <p>gosx-notifier 297</p> <p>Installation 297</p> <p>Code sample 297</p> <p><b>Chapter 19: Ten Great Go Resources</b><b> 299</b></p> <p>The Official Go Website 299</p> <p>Go by Example 300</p> <p>A Tour of Go 300</p> <p>The Go Frequently Asked Questions 300</p> <p>The Go Playground 300</p> <p>Go Bootcamp 301</p> <p>Effective Go 301</p> <p>Gophercises 301</p> <p>Tutorialspoint 301</p> <p>Stack Overflow 302</p> <p>Index 303</p>
<p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p>
<p><b>Get going with one of today’s top languages!</b></p><p>This book walks with you as you take your first steps in the fast-growing coding language, Go. You’ll work through all the basics, and then you’ll build job-ready skills for making applications that work in the cloud! Go is great at scooping up data from around the web and putting it into users’ hands. With this book at your side you’ll become adept at accessing, structuring, and serving data by writing applications that are easy to maintain and understand. Go is in high demand—this primer will put it on your resume.</p><p><b>Inside. . .</b></p> <ul><b><li>Learn the fundamentals of Go</li><li>Write clean, efficient functions</li><li>Structure and organize data</li><li>Find out all about Goroutines</li><li>Discover third-party Go packages</li><li>Work with web services</li><li>Link up with REST APIs</li></b></ul>

Diese Produkte könnten Sie auch interessieren:

Chemie in Lebensmitteln
Chemie in Lebensmitteln
von: Johannes Friedrich Diehl
PDF ebook
61,99 €
Lebensmittelführer
Lebensmittelführer
von: Günter Vollmer, Gunter Josst, Dieter Schenker, Wolfgang Sturm, Norbert Vreden
PDF ebook
16,99 €
Lebensmittelführer
Lebensmittelführer
von: Günter Vollmer, Gunter Josst, Dieter Schenker, Wolfgang Sturm, Norbert Vreden
PDF ebook
16,99 €