O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hands-On Go Programming

Book Description

Learn Go programming with concise examples providing solutions to many common fundamental problems.

Learn Go programming with concise examples providing solutions to common problems

Key Features

  • Study Go programming with the help of short, modular, and concise recipes
  • Overcome the most common challenges in Go
  • Exploit the most exciting features of Go such as Goroutines

Book Description

With its C-like speed, simplicity, and power for a growing number of system-level programming domains, Go has become increasingly popular among programmers. Hands-On Go Programming teaches you the Go programming by solving commonly faced problems with the help of recipes. You will start by installing Go binaries and get familiar with the tools used for developing an application. Once you have understood these tasks, you will be able to manipulate strings and use them in built-in function constructs to create a complex value from two floating-point values. You will discover how to perform an arithmetic operation date and time, along with parsing them from string values. In addition to this, you will cover concurrency in Go, performing various web programming tasks, implementing system programming, reading and writing files, and honing many fundamental Go programming skills such as proper error handling and logging, among others. Whether you are an expert programmer or newbie, this book helps you understand how various answers are programmed in the Go language.

What you will learn

  • Manipulate string values and escape special characters
  • Work with dates, times, maps, and arrays
  • Handle errors and perform logging
  • Explore files and directories
  • Handle HTTP requests and responses
  • Perform CRUD operations on a relational database

Who this book is for

Hands-On Go Programming is for you if you are a software developer interested in learning Go language, or anyone who wants to explore practical code examples.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Go Programming
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributor
    1. About the author
    2. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  6. Getting Started with Go
    1. Installing Go binaries
    2. A quick look at the Go language
    3. Summary
  7. Manipulating String Values
    1. Trimming spaces from the beginning and end of a string
    2. Extracting sub-strings from a string value
    3. Replacing parts of a string
    4. Escaping characters in a string
    5. Capitalizing string values
    6. Summary
  8. Type Conversions
    1. Converting a Boolean into a String
    2. Converting integer and float values into a string
      1. Converting an integer value into a string value
      2. Converting a float value into a string value
    3. Parsing string values to Boolean values
    4. Parsing string values to integer and float types
      1. Parsing string values to integer types
      2. Parsing string values to float numbers
    5. Converting a byte array into a string
    6. Summary
  9. Date and Time
    1. Finding today's date and time
    2. Adding and subtracting from a date
      1. Adding to the date
      2. Subtracting from the date
      3. Adding time
    3. Finding the difference between two dates
    4. Parsing dates and times from strings
    5. Summary
  10. Maps and Arrays
    1. Extracting unique elements from an array
    2. Finding an element from an array
    3. Reverting an array
    4. Iterating over an array
    5. Converting a map into an array of keys and values
    6. Merging arrays
    7. Merging maps
    8. Testing for the presence of a key in a map
    9. Summary
  11. Errors and Logging
    1. Creating custom error types
    2. The try...catch equivalent in Go
    3. Doing simple logging in your application
    4. Gracefully dealing with panics
    5. Summary
  12. Files and Directories
    1. Checking the existence of a file
    2. Reading the entire contents of a text file
    3. Writing to a file
    4. Creating temporary files
    5. Counting lines in a file
    6. Reading a particular line in a file
    7. Comparing the contents of two files
    8. Deleting a file
    9. Copying or moving a file
    10. Renaming files
    11. Deleting a directory and its contents
    12. Listing all the files under a directory
    13. Summary
  13. Concurrency
    1. Running multiple functions concurrently
    2. Passing data between concurrently running functions
    3. Waiting for all concurrent functions to finish
    4. Selecting the results of concurrent functions
    5. Summary
  14. System Programming
    1. Catching signals
    2. Running child processes
    3. Processing command-line arguments
    4. Summary
  15. Web Programming
    1. Downloading a web page from the internet
    2. Downloading files from the internet
    3. Creating a simple web server
    4. Creating a simple file server
    5. Summary
  16. Relational Databases
    1. Reading data from databases
    2. Inserting data into databases
    3. Updating data in databases
    4. Deleting data from databases
    5. Summary
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think