...
- Udemy - A search for "golang"
- Looks like there are a couple of good options...
- How I Start - Go
Go: The Complete Developers Guide
- https://www.udemy.com/go-the-complete-developers-guide/learn/v4/content
- This was the highest-rated intro to Go on Udemy.
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
- No video, just text.
- You can find the completed version of all the examples in this course here: https://github.com/StephenGrider/GoCasts
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.
- package main
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:
- How do we run the code in our project?
- What does 'package main' mean?
- What does 'import "fmt"' mean?
- What's that 'func' thing?
- 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:
Go to https://github.com/StephenGrider/GoCasts/tree/master/diagrams
Open the folder containing the set of diagrams you want to edit
Click on the ‘.xml’ file
Click the ‘raw’ button
Copy the URL
Go to https://www.draw.io/
On the ‘Save Diagrams To…’ window click ‘Decide later’ at the bottom
Click ‘File’ -> ‘Import From’ -> ‘URL’
Paste the link to the XML file