In the first program, we will print out the classic message: “Hello world”. This is the full source code:
1 2 3 4 5 6 7 8 | package main import "fmt" func main() { fmt.Println("hello world") } |
To run the program, write the code in the file hello-world.go and use go run.
1 2 3 | $ go run hello-world.go hello world |
Sometimes we want to build our program into a binary file. This can be done using go build.
1 2 3 4 | $ go build hello-world.go $ ls hello-world hello-world.go |
Then we run the file directly:
1 2 3 | $ ./hello-world hello world |
Now we can build and run a basic Go application. Learn more with the next examples.
The next example: Values
Source: https://github.com/nhannguyen09cntt/gobyexample/tree/master/examples/hello-world
Refer: https://4rum.vn/t/tutorial-go-by-example-hello-world/500 https://github.com/mmcgrana/gobyexample