Sage-Code Laboratory
index<--

Go Examples

Next examples are ready for study on Go Playground website. You can run them on-line and check the output. You can create new examples or modify these ones and re-share. All these examples are open sources created by volunteers.

Page bookmarks



Links to: Go Playground

00 Syntax demo Description
hello world How to print a message
variables How to declare variables
constants How to declare constants
01 Control flow
for loop Repetitive block statement
switch Multi-path value selector statement
conditional Conditional branching, if statement
02 Functions
functions How to create a function in GoLang
return How to define and capture multiple results
varargs How to define variadic function
closure How to use high order functions
recursion How to create a recursive function
pointers How to define and use pointers in functions
03 Collections
array How to define arrays
slices How to define slices
maps How to define a hash map
range How to traverse a collection using range
strings How to create strings & runes
sorting Using built-in .sort() method
custom sort Using a callback function to sort()
04 Objects
struct How to declare a data structure
methods How to define bounded functions
interfaces How to define interfaces
embedding How to define a nested struct
generics How to define generic struct
05 Error Handling
errors Define custom error using: errors.New()
panic How to create an exception
defer How to postpone execution of a statement
recover How to handle errors and avoid crash
06 Data processing
string functions String processing functions
formating String "fmt" package and format technique
templates Text template and format technique
regex How to use regular expressions
JSON How to parse JSON data
XML How to work with XML format
05 Concurrency
goroutines Learn how to use "go" to start a concurent function
channels Learn how to declare channels
buffers How to create a buffered channel
synchronization How to synchronize go routines using channels
direction How to define uni-directional channels
select How to handle multiple channels
timeouts Learn how to stop waiting for a go routine
non-blocking How to create non-blocking channels
closing How to close a channel and synchronize
range & channel How to creat a range over channel
timers How to create a timer: time.newTimer()
tikers How to create a ticker: time.NewTicker()
worker pool How to use worker pool with goroutine.
wait group https://gobyexample.com/waitgroups
rate limiting How to control resource utilization
atomic counters Using sync/atomic alternative to channels
mutex Use "mutex" as alternative to channels
stateful goroutines How to manage state using channels
07 Working with files
reading How to read files
writing How to write files
filter How to create "line filter" app
path How to work with path/filepath package
folder How to create/remove a folders
temporary How to work with temporary files
embeded How to work with embeded files
ReadDir() How to list files using ioutil package
Walk() How to list files using filepath package
ReadDir() How to list files using file.ReadDir function

Homework: Take the Quiz