Skip to main content

Posts

Showing posts from October 21, 2019

Hello World in Go

Your First Program Traditionally the first program you write in any programming language is called a “Hello World” program – a program that simply outputs  Hello World  to your terminal. Let's write one using Go. First create a new folder where we can store our program. Create a folder named  ~/src/go_example . (Where  ~  means your home directory) From the terminal you can do this by entering the following commands: mkdir src/go_example touch src/go_example/main.go Using your text editor type in the following in the main.go: package main import "fmt" // this is a comment func main() { fmt.Println("Hello World") } Open up a new terminal and type in the following: cd src/go_example go run main.go You should see  Hello World  displayed in your terminal. The  go run  command takes the subsequent files (separated by spaces), compiles them into an executable saved in a temporary directory and then runs the program....