Goprogramming Notes
Goprogramming Notes
Basics
Statically typed, compiled language
Designed for concurrent and parallel programming
Simple and minimalistic syntax
Uses goroutines and channels for concurrency
Data Types
Basic types: int, float64, bool, string
Composite types: arrays, slices, maps, structs
Reference types: pointers, interfaces
Control Structures
Conditional statements: if, if-else, switch
Loops: for (no while loop)
Range keyword for iterating over arrays, slices, and maps
Functions
Functions are first-class citizens
Can return multiple values
Supports closures and anonymous functions
Concurrency
Goroutines: lightweight threads managed by Go runtime
Channels: used for communication between goroutines
Select statement: used for handling multiple channels
Error Handling
Errors are values that can be returned from functions
Panic and recover functions for handling runtime errors
Packages
Go has a vast standard library
Third-party packages can be installed using go get
Each package has its own namespace
Object-Oriented Programming
No classes or inheritance
Structs can have methods
Interfaces define a set of methods
Key Concepts
Goroutines
Channels
Select statement
Error handling
Packages
Interfaces
Go Commands
go run: compiles and runs Go code
go build: compiles Go code into an executable
go test: runs Go tests
go get: installs third-party packages
Best Practices
Use meaningful variable names
Handle errors properly
Use goroutines and channels for concurrency
Follow Go's coding standards