Go is an open source programming language designed for building scalable, secure, and reliable software. Go combines the performance of C with features like garbage collection, concurrency, and a strong type system.
How to Go is a modern, hands-on language reference. Master everything from syntax to advanced patterns through annotated examples.
Hello, World!
This is the traditional first program for learning a new programming language.
In Go, you can create a simple "Hello, World!" program like this:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}To run this program, save it to a file named hello.go and use the command:
go run hello.goHello, World!Program Structure
| Component | Purpose | Required |
|---|---|---|
package main | Declares this is an executable program | Yes (for executables) |
import "fmt" | Imports the fmt package for formatted I/O | Only if using fmt functions |
func main() | Entry point of the program | Yes (for executables) |
fmt.Println() | Prints text followed by a newline | No |
Common Go Commands
| Command | Description |
|---|---|
go run hello.go | Compile and run the program directly |
go build hello.go | Compile to an executable binary |
go fmt hello.go | Format the code according to Go standards |
go mod init myapp | Initialize a new Go module |