Packages, variables and functions
Download
In my case, installed go1.14.darwin-amd64.pkg
Sample code
hello.go
package main
import "fmt"
func main() {
fmt.println("hello, world")
}Test your Installation
$ go build hello.go # build
$ ./hello # run
# hello, worldGo tour
Go tour?
A guide program on how to use go.
After above command, you can find tour in go/bin/. Double click to run.
Tour > Basics > Packages, variables and functions.
Packages
Every Go program is made of packages.
Programs start running in package
mainImports can also be in multiple import statements.
Exported names
When importing a package, you can only accessible to its Exported names. Which begins with a capital letter i.e., Pi
Functions
Variables
Basic types
Zero value
Variables declared without an explicit value are given intial value. this is called zerovalue.
Type conversions
The expression T(v) converts the value v to the type T.
Type inference
The variable's type is inferred from the value on the right hand side.
Constants
Constant cannot be declared using := syntax.
For more insights
Last updated
Was this helpful?