- Idea behind Golang is to minimize the number of lines of code.
- Primary use of Go is to write server-side programs or command line programs.
- Creators of Golang - Ken Thomson, Rob Pike and Robert Griesemer
- Modern standard library
- Compile to single native binary - no runtime required.
- Has garbage collection built in
- Simple, strongly-typed, procedural language with object oriented features - very few language features have been added since 1.0 release
- Built-in concurrency
- Fast to compile and run quickly
- Some popular Go projects:
- K8s
- Docker
- Prometheus
To setup an IDE for Go - Visual Studio Code is a good choice.
- Install VS Code from https://code.visualstudio.com/download
- Setup VS Code for Go development by installing the “Go” Extension from Microsoft
- Also install the Go packages by:
- Cntl + Shift+ P or View > Command Pallet
- Enter: Go: Install/Update Tools
- Select All and Click OK.
- Go to Settings for Go Extensions - Look up “Infer GoPath” setting and enable/check it.
Now you should be able to use the IDE to edit and compile/run go code.
Also watch this screencast https://www.youtube.com/watch?v=XCsL89YtqCs on writing, building, installing and testing Go code.
Set GOPATH environment variable to a directory where your go code will reside.
For example: ~/go directory.
export GOPATH=~/go
Under ~/go create 3 directories that go requires:
src, pkg and bin
At any point look for the go documentation as:
> go doc fmt.Println
Following is a hello world program that will go in ~/go/src directory.
package main
import "fmt"
func main() {
fmt.Println("Hello, World")
}
In VS Code launch the Terminal (Cntl + Shift + `) or Terminal > New Terminal.
To build the program:
> go build hello.go
> ./hello
To directly run the program and not build it first:
> go run hello.go
No comments:
Post a Comment