Variables, Types and Packages
var age int = 25nvar price float64 = 19.99nname := "Tutoline" // short declaration -- type is inferrednisActive := true
Go is statically typed like Java or C++, but the := short declaration operator infers the type automatically, similar in feel to auto in C++ or var in JavaScript — you will use := for the large majority of variable declarations inside a function.
Common types
int,int64— whole numbersfloat64— decimal numbersstring— textbool— true/false
Every declared variable must be used
func main() {n unused := 5n // Error: unused is declared and not usedn}
This surprises newcomers coming from other languages — Go’s compiler refuses to build code with an unused local variable, treating it as a near-certain mistake rather than a harmless warning. It feels strict at first, but it genuinely does catch real bugs (like a variable you meant to use but forgot to).
Packages and imports
import (n "fmt"n "strings"n)nnfunc main() {n upper := strings.ToUpper("tutoline")n fmt.Println(upper)n}
Go organizes code into packages, and the standard library covers an enormous amount of everyday functionality — strings, strconv (type conversion), net/http (a full HTTP server, no framework required), and many more, all included with the language itself.
Exported vs unexported names
A function or variable starting with a capital letter (like fmt.Println) is exported — visible to code outside its package. A lowercase name is unexported — private to its own package. This single naming convention replaces the separate public/private keywords you would find in Java or C++.