Go Language Tutorial

Go is an open source programming language that makes it easy to construct simple, reliable, and efficient software.

Go was developed in late 2007 by Robert Griesemer, Rob Pike, Ken Thompson, and later joined by Ian Lance Taylor, Russ Cox and others, and was finally open sourced in November 2009, and Go 1 stable was released in early 2012 Version. Go development is now fully open and has an active community.

Our Go tutorial includes all topics of Go language, how to install go, such as go syntax if-else, for, for for-range, go break, continue, struct, interface, map, etc.

Go language features

  • Simple, fast and secure
  • Parallel, interesting, open source
  • Memory management, array safety, fast compilation
  • Automatic garbage collection
  • Richer built-in types
  • Function with multiple return values
  • error handling
  • Anonymous functions and closures
  • Types and Interfaces
  • concurrent programming
  • reflection  
  • language interactivity

Go language usage

The Go language was designed as a systems programming language for hosting web servers, storage clusters, or giant central servers for similar purposes.

For the field of high-performance distributed systems, Go language undoubtedly has higher development efficiency than most other languages. It provides massive parallel support, which is perfect for game server development.

The basic structure of a Go program consists of the following parts:

  • package declaration
  • import package
  • variable
  • Statements and Expressions
  • function
  • Notes

The first Go program

Next, let’s write the first Go program hello.go (the extension of the Go language source file is .go), the code is as follows:

package main

import "fmt"

func main(){
    fmt.Println("Hello, World!")

To execute Go code you can use the go run command.

Executing the above code outputs:

$ go run hello.go 
Hello, World!

Additionally, we can use the go build command to generate binaries:

$ go build hello.go 
$ ls
hello    hello.go
$ ./hello 
Hello, World!