Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


Go: The Complete Developers Guide

Section 1: Getting Started

1. How to Get Help

  • No video, just text.
  • There are three ways to get help:
    • Post in the Q&A discussion
    • Email me: <email address redacted>
    • Message me on Udemy.

2. Link to Completed Code

3. Environmental Setup

  • We are going to install Go, then we'll install VSCode (an IDE), then we'll configure VSCode, then we'll write some code.
    • He highly recommends trying VSCode because it has the best integration with Go.
  • To install Go, go to golang.org/dl
  • Just keep hitting "Next" for the installer, there's nothing we need to configure.

4. VSCode Installation

  • To verify Go was installed correctly, start a terminal / command prompt window and type "go" and hit Enter. You should see a help message show up on the screen.
  • To install VSCode, go to code.visualstudio.com

5. Go Support in VSCode

  • VSCode doesn't start out with any support for Go.
  • To add this support, go to View → Extensions, and search for "go".
  • Download the extension with the title "Go", the description "Rich Go language support..." and over 1 million downloads.
  • Restart VSC.
  • Make sure you have a code editor window open (do File → New File if you don't).
  • In the bottom right corner, click "Plaintext" and switch it to "Go", and in the same place where "Plaintext" showed up you'll see an error saying "Analysis tools missing". Click the error message and then click "Install" on the dialogs that pop up.

Section 2: A Simple Start

6. Boring Ol' Hello World

  • We're going to start with a simple "Hello World" example in this video but in the next few videos we're going to do a deep dive on how Go is working behind the scenes.
  • He goes to File → Open and creates a new folder named "helloworld" to house this project.
    • NW: In my editor I didn't have an "Open" option, just "Open File" and "Open Folder", so I chose the latter.
  • You should see the folder show up in the left sidebar (the "Explorer tab").
  • He clicks a little "Add file" button next to the name of his project in the Explorer tab and names it "main.go". 
  • He writes out the code and says we'll discuss each line in-depth in the next few videos:
    • package main

      import "fmt"

      func main() {
          fmt.Println("Hi there!")
      }
    • He says you must use double-quotes, not single quotes, in both the import statement and the Println statement.

7. Five Important Questions

  • He studied the Hello World program ahead of time and came up with five basic questions we can ask that will give us a good sense of what the program is doing:
    1. How do we run the code in our project?
    2. What does 'package main' mean?
    3. What does 'import "fmt"' mean?
    4. What's that 'func' thing?
    5. How is the main.go file organized?
  • He then starts answering question 1.
  • He switches to a terminal navigated to his project folder.
  • He runs "go run main.go"
    • NW: When I tried this I ran into a minor problem in that my code had not been auto-saved like it is in PyCharm, so it didn't work until I figured out that that was happening.
  • He shows several other go CLI commands that we'll be using.
  • "go run" is used to compile and immediately execute one or two files, without generating an executable file.
  • "go build" compiles, but does not execute, go files. It will generate an executable file.
  • "go fmt" formats all of the code in each file in the current directory.
  • "go install" compiles and 'installs' a package.
  • "go get" downloads the raw source code of someone else's package.
  • "go test" runs any tests associated with the current project.

8. Go Packages

  • We're going to talk about what "package" means and why we chose the name "main".
  • A package can be thought of as a project or workspace.
    • A package can have many Go source code files in it.
  • Every file that belongs to a package must have its first line declare the package it is a part of.
  • As for why we chose "main":
  • There are two types of packages: executable packages and reusable packages.
  • Executable packages generate an executable we can run.
  • Reusable packages are used as helpers / libraries.
  • The name of the package that you use determines whether you're creating an executable or reusable package.
  • In particular, the word "main" for a package is what designates a package as executable.
  • Any other name for a package will create a reusable package.
  • An executable package must have a function called "main".

9. Import Statements

  • The import statement is used to give our package access to code contained in another package.
  • "fmt" is a standard library included with Go. It stands for "format". It's used for printing out information.
  • We can import both standard packages that are included with Go as well as packages that are not official and have been authored by other individuals.
  • We can learn more about the standard packages by going to golang.org/pkg
  • We are going to be looking at these official docs a lot, because a lot of learning Go is learning how these standard packages work.

10. File Organization

  • So, what's that 'func' thing?
    • 'func' is short for "function". Functions in Go work just like functions in other languages.
  • How is the main.go file organized?
    • It's always the same pattern in every file:
    • At the very top we have a "package ..." declaration.
    • Then we'll import other packages we need.
    • Then we'll declare functions.

Quiz 1

  • What is the purpose of a package in Go?
  • What is the special name we use for a package to tell Go that we want it to be turned into a file that can be executed?
  • The one requirement of packages named "main" is that we...
  • Why do we use "import" statements?

11. How to Access Course Diagrams

  • No video, just text.
  • How to use the course diagrams:

Section 3: Deeper Into Go

12. Project Overview

13. New Project Folder

14. Variable Declarations

15. Functions and Return Types

16. Slices and For Loops

17. OO Approach vs. Go Approach

18. Custom Type Declarations

19. Receiver Functions

20. Creating a New Deck

21. Slice Range Syntax

22. Multiple Return Values

23. Byte Slices

24. Deck to String

25. Joining a Slice of Strings

26. Saving Data to the Hard Drive

27. Reading From th Hard Drive

28. Error Handling

29. Shuffling a Deck

30. Random Number Generation

31. Testing With Go

32. Writing Useful Tests

33. Asserting Elements in a Slice

34. Testing File IO

35. Project Review

Section 4: Organizing Data With Structs

36. Structs in Go

37. Defining Structs

38. Declaring Structs

39. Updating Struct Values

40. Embedding Structs

41. Structs with Receiver Functions

42. Pass By Value

43. Structs with Pointers

44. Pointer Operations

45. Pointer Shortcut

46. Gotchas With Pointers

47. Reference vs. Value Types

Section 5: Maps

48. What's a Map?

49. Manipulating Maps

50. Iterating Over Maps

51. Differences Between Maps and Structs

Section 6: Interfaces

52. Purpose of Interfaces

53. Problems Without Interfaces

54. Interfaces in Practice

55. Rules of Interfaces

56. Extra Interface Notes

57. The HTTP Package

58. Reading the Docs

59. More Interface Syntax

60. Interface Review

61. The Reader Interface

62. More on the Reader Interface

63. Working with the Read Function

64. The Writer Interface

65. The io.Copy Function

66. The Implementation of io.Copy

67. A Custom Writer

Section 7: Channels and Go Routines

68. Website Status Checker

69. Printing Site Status

70. Serial Link Checking

71. Go Routines

72. Theory of Go Routines

73. Channels

74. Channel Implementation

75. Blocking Channels

76. Receiving Messages

77. Repeating Routines

78. Alternative Loop Syntax

79. Sleeping a Routine

80. Function Literals

81. Channels Gotcha!