Getting started
Basic types
Variables
Constants
Strings
Pointers
Arrays
Slices
Maps
Structs
Interfaces
Empty interface
if, switch, goto
for, while loops
range statement
Functions
Methods
Error handling
Defer
Panic and recover
Concurrency
Channels and select
Mutex
Packages
Files and I/O
Time and date
Command line arguments
Logging
Executing commands
Hex, base64 encoding
JSON
XML
CSV
YAML
SQL
HTTP Client
HTTP Server
Text and HTML templates
Reflection
Context
Package fmt
OS Signals
Testing
Calling C from GO with cgo
Profiling using go tool pprof
Cross compilation
Conditional compilation with build tags
Inlining functions
sync.Pool for better performance
gob
Plugin
HTTP server middleware
Protobuf in Go
Console I/O
Cryptography
Images (PNG, JPEG, BMP, TIFF, WEBP, VP8, GIF)
The Go Command
go fmt
go run
go build
Specify OS or Architecture in build:
Build multiple files
Building a package
go clean
go get
go env
go test
Testing code with CI services
Windows GUI programming
Contributors

go build

suggest change

go build will compile a program into an executable file.

To demonstrate, we will use a simple Hello World example main.go:

package main

import fmt

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

To compile the program run: go build main.go

build creates an executable program, in this case: main or main.exe. You can then run this file to see the output Hello, World!. You can also copy it to a similar system that doesn’t have Go installed, make it executable, and run it there.

Specify OS or Architecture in build:

You can specify what system or architecture to build by modifying the env before build:

$ env GOOS=linux go build main.go # builds for Linux
$ env GOARCH=arm go build main.go # builds for ARM architecture

Build multiple files

If your package is split into multiple files and the package name is main (that is, it is not an importable package), you must specify all the files to build:

$ go build main.go assets.go # outputs an executable: main

Building a package

To build a package called main, you can simply use:

$ go build . # outputs an executable with name as the name of enclosing folder

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents