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.
Introduction to Go Examples
Page bookmarks
Links to: Go Playground
Syntax Basics
Control Flow Examples
| |
for loop |
Repetitive block statement |
| |
switch |
Multi-path value selector statement |
| |
conditional |
Conditional branching, if statement |
Functions Examples
| |
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 |
Collections Examples
| |
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() |
Objects Examples
Error Handling Examples
| |
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 |
Data Processing Examples
| |
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 |
Concurrency Examples
Working with Files Examples
| |
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 |