Learn the structure of a Go program in this video. The instructor goes over the Hello World program and discusses every line from the import statement, to the package name, to the function definition.
- [Instructor] Let's take a look at the small Go program and break it down line by line. The first line is a comment. You can either use single-line comments, like this, or multi-line comments, which start with a forward slash and an asterisk and end with an asterisk and a forward slash, very much like C++ or Java. Line three is package main. Go code is organized in packages. This helps in big projects, allowing teams to work on parts of the system independently. The main package has a special meaning in Go and it will make your code compile for an executable and not the package.
Line five is an import statement. Go is a very simple language, and by itself, does not have many built-in functions. Most of the code you'll be using will be in packages. Go comes with a start library which contains many packages. In line six, we import the f m t package, which is pronounced fmt. The fmt package contains functions for formatted printing.
In line nine we have function main. We define a function with the func keyword. The body of the function is enclosed in curly braces. The function main also has a special meaning in Go. It will be executed by the Go runtime when the program starts. The print l n function from the fmt package prints its argument in a new line. You need to prefix the function name print l n with the package it came from. Unlike C++ or Java, you don't need to place a semicolon at the end of the line.
The message printed out is a string. Strings in Go starts and end with double quotes. Go strings are Unicode, which means you don't need special code to support non-English languages.
- Go basic types, conditionals, and loops
- Go functions
- Object-oriented programming with Go
- Error handling
- Concurrent programming with channels
- Testing and project management
- Networking with JSON and HTTP
Skill Level Beginner
Programming Foundations: Fuzzy Logicwith Erin Colvin41m 50s Intermediate
Getting started1m 34s
1. Getting Started
2. Go Basics
5. Error Handling
7. Project Management
Next steps1m 12s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.