Leanpub Header

Skip to main content

Go, from the beginning

from o to hero

In this book you will learn the following:

  • Build Console apps
  • Create Web APIs
  • Test your code
  • Create and publish reusable packages that others can consume
  • Organize your files in a project
  • Work with files and directories
  • Parse text with the string library and regular expressions.

The author is letting you choose the price you pay for this book!

Pick Your Price...
PDF
EPUB
WEB
6,361
Readers
174
Pages
About

About

About the Book

Price

Pick Your Price...

Minimum price

Free!

$7.99

You pay

$0.00

Cause gets

$0.00
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 0)

0
The author will earn $0.00 from your purchase!
You can get credits monthly with a Reader Membership

Author

About the Author

Chris Noring

I'm a Senior Cloud Advocate Lead currently working at Microsoft.

I have:

  • 15 years' experience in the tech Industry.
  • Published several books on Angular, React and now Go.

Read more from me

I love programming and I love to teach.

You can find my written work at places like:

  • github.com/softchris
  • github.io/softchris
  • dev.to/softchris

Contents

Table of Contents

Your first program

  1. Introduction
  2. A history of Go
  3. What is it used for though?
  4. References
  5. Features
  6. Install Go
  7. A Go program
  8. Commands
  9. Summary
  10. ? Challenge
  11. Review & Self Study
  12. Assignment
  13. Solution

Using variables

  1. Introduction
  2. Declare variables
  3. Assign variables
  4. Data types
  5. String interpolation
  6. Assignment - define some variables and print them out
  7. ? Challenge
  8. Review & Self Study
  9. Solution

Flow control

  1. Introduction
  2. Flow control
  3. The if construct
  4. Using else if
  5. Multiple expressions
  6. Assignment - create a program that tests your Boolean logic
  7. ? Challenge
  8. Solution
  9. Review & Self Study

Converting between types

  1. Introduction
  2. Why convert between types
  3. Use case - command-line arguments
  4. Convert from string to int with strconv
  5. Parse string to int
  6. Integer to string
  7. Additional parsing
  8. Assignment
  9. Solution
  10. ? Challenge

Working with loops

  1. Introduction
  2. The case for looping statements
  3. The for loop
  4. Repeat until the condition is met with while
  5. Using for-each over a range
  6. Controlling the loop with continue and break
  7. Assignment - create a command line loop
  8. ? Challenge
  9. Solution

Reading user input

  1. Introduction
  2. User input
  3. Managing user input with fmt
  4. Reading one input
  5. Reading multiple inputs
  6. Scanf(), scan the input with formatters
  7. Learn more
  8. Assignment - read user input
  9. ? Challenge
  10. Solution

Using functions

  1. Introduction
  2. Why functions
  3. Your first function main()
  4. The anatomy of a function
  5. Adding a return type
  6. Multiple returns
  7. Assignment - adding a function to a program
  8. Solution

Handling errors

  1. Introduction
  2. Errors
  3. Crash the program with panic()
  4. Improve the error handling
  5. Use the error pattern with the errors package
  6. Assignment I - add error handling
  7. Solution I
  8. Assignment II - improve error logging
  9. Solution II

Arrays and slices

  1. Introduction
  2. Arrays
  3. Declare an array
  4. Accessing elements
  5. Length and capacity
  6. Slices
  7. Assignment - store log entries
  8. Solution

Structs

  1. Introduction
  2. Why structs
  3. Defining a struct
  4. Embedding a struct
  5. Adding implementation to structs
  6. Assignment - defining a struct
  7. Solution

Using maps

  1. Introduction
  2. The use case for a map
  3. Creating a map
  4. Read a value by key
  5. Iterate over a map
  6. Delete an entry
  7. Assignment - build a phone book
  8. Solution
  9. Challenge

Interfaces

  1. Introduction
  2. Interface
  3. Interface - describing a behaviour
  4. Implement an interface
  5. Type assertions
  6. Change a value
  7. Assignment
  8. Solution

Your first project

  1. Introduction
  2. Module use cases
  3. Consume internal files
  4. Creating a project
  5. The import statement
  6. Assignment - create a project
  7. Solution
  8. Challenge

Consume an external module

  1. Introduction
  2. External module
  3. Import module
  4. Use it in code
  5. Assignment - consume an external module
  6. Solution
  7. Challenge

Create a module meant for sharing

  1. Introduction
  2. Create a module
  3. Assignment - create a module meant for sharing and consume it
  4. Challenge

Test your code in Go

  1. Introduction
  2. Why we test
  3. What Go provides
  4. Your first test
  5. Control the test run
  6. Coverage
  7. Learn more
  8. Challenge

Working with JSON

  1. Introduction
  2. JSON
  3. Reading JSON
  4. Writing JSON
  5. Assignment
  6. Solution
  7. ? Challenge
  8. Learn more

Build a Web API

  1. Introduction
  2. Web API
  3. The net/http library
  4. Responding to a request
  5. Working with the request
  6. ServeMux, a better way
  7. Assignment - build a first web app
  8. Solution
  9. Challenge

Better logging with a logging library

  1. Introduction
  2. Reasons to log
  3. What to log
  4. Using log
  5. Assignment
  6. Solution

Working with strings

  1. Handling special characters
  2. Inspect with Contains()
  3. Parsing with Split()
  4. Presentation
  5. Assignment
  6. Solution

Use regular expressions to parse text

  1. What is RegEx and what to use it for
  2. Why use RegEx
  3. Where is it used ?
  4. Your first RegEx
  5. Character classes
  6. Repetition
  7. Anchors and boundaries
  8. Groups
  9. Named groups
  10. Assignment - create a Go program that parses a URL
  11. Replacing
  12. Assignment - replace content
  13. Solution II

Goroutines and channels

  1. Introduction
  2. Concurrency, what’s the benefit
  3. Goroutines
  4. Channels
  5. Assignment - SearchFiles() with channels
  6. Challenge
  7. Solution

Working with a database

  1. Introduction
  2. Select a sqlite driver
  3. Use sqlite3 from the console
  4. Talking to your database via Go.
  5. Assignment
  6. Solution

Read and write to files

  1. Introduction
  2. Read a text file
  3. Write text to a file
  4. Append to a file
  5. Assignment
  6. Solution
  7. Challenge

Perform operations on files and directories

  1. Introduction
  2. File information
  3. Copy file
  4. Rename
  5. Remove file
  6. Create dir
  7. Read dir
  8. Assignment
  9. Solution

Causes

Causes Supported

Tree-Nation

Tree-Nation Tree-Nation

You reforest the world

https://tree-nation.com
Tree-Nation is the largest reforestation platform enabling citizens and companies to plant trees around the world.
Tree-Nation’s mission is to reforest the world. The organisation offers people the possibility to select from over 300 different tree species which can be planted in 50 different reforestation projects located in 6 different continents. In every project, the species are carefully selected according to the specific benefits they bring for the environment and to the local population. Each tree planted on the Tree-Nation platform is assigned its own unique URL, which means the species, the location, the plantation project information and the CO2 compensation values can be tracked throughout the lifetime of the tree. Since its inception in 2006, more than 130,000 users and more than 2,200 companies have planted 5 million trees using its platform.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub