{"id":15127487,"url":"https://github.com/simonwaldherr/golang-examples","last_synced_at":"2026-10-19T11:48:43.055Z","repository":{"id":8048815,"uuid":"9459712","full_name":"SimonWaldherr/golang-examples","owner":"SimonWaldherr","description":"Go(lang) examples - (explain the basics of #golang)","archived":false,"fork":false,"pushed_at":"2026-07-29T13:45:37.000Z","size":5365,"stargazers_count":1723,"open_issues_count":6,"forks_count":458,"subscribers_count":52,"default_branch":"master","last_synced_at":"2026-10-10T16:40:02.101Z","etag":null,"topics":["education","examples","go","golang","hacktoberfest","hacktoberfest-accepted","howto","learning","programming-language"],"latest_commit_sha":null,"homepage":"https://simonwaldherr.github.io/golang-examples/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SimonWaldherr.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"claude":null,"gemini":null,"cursor":null,"copilot":null,"dco":null,"cla":null,"disclosure":null},"funding":{"github":"simonwaldherr","patreon":"simonwaldherr","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"SimonWaldherr","issuehunt":null,"otechie":null,"custom":["https://flattr.com/@SimonWaldherr"]}},"created_at":"2013-04-15T22:42:13.000Z","updated_at":"2026-10-08T00:59:44.000Z","dependencies_parsed_at":"2026-08-31T02:41:56.451Z","dependency_job_id":null,"html_url":"https://github.com/SimonWaldherr/golang-examples","commit_stats":{"total_commits":210,"total_committers":52,"mean_commits":4.038461538461538,"dds":0.3380952380952381,"last_synced_commit":"e47c72cc35d6e30b6a0a2f6565556d7ba27dd621"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"purl":"pkg:github/SimonWaldherr/golang-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonWaldherr%2Fgolang-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonWaldherr%2Fgolang-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonWaldherr%2Fgolang-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonWaldherr%2Fgolang-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimonWaldherr","download_url":"https://codeload.github.com/SimonWaldherr/golang-examples/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonWaldherr%2Fgolang-examples/sbom","scorecard":{"id":130245,"data":{"date":"2025-08-11","repo":{"name":"github.com/SimonWaldherr/golang-examples","commit":"3631c688754126ee7a1f998eefe59297b6d0858f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.9,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":1,"reason":"Found 3/21 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: containerImage not pinned by hash: advanced/microservice_example/Dockerfile:1: pin your Docker image by updating golang:alpine to golang:alpine@sha256:c8c5f95d64aa79b6547f3b626eb84b16a7ce18a139e3e9ca19a8c078b85ba80d","Warn: goCommand not pinned by hash: test.sh:161","Info:   0 out of   1 containerImage dependencies pinned","Info:   0 out of   1 goCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 12 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-16T05:06:34.141Z","repository_id":8048815,"created_at":"2025-08-16T05:06:34.141Z","updated_at":"2025-08-16T05:06:34.141Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":344872684,"owners_count":38356429,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-10-03T21:59:58.778Z","status":"online","status_checked_at":"2026-10-19T02:00:06.414Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["education","examples","go","golang","hacktoberfest","hacktoberfest-accepted","howto","learning","programming-language"],"created_at":"2024-09-26T02:03:59.544Z","updated_at":"2026-10-19T11:48:43.042Z","avatar_url":"https://github.com/SimonWaldherr.png","language":"Go","funding_links":["https://github.com/sponsors/simonwaldherr","https://patreon.com/simonwaldherr","https://liberapay.com/SimonWaldherr","https://flattr.com/@SimonWaldherr"],"categories":[],"sub_categories":[],"readme":"# Golang-Examples\n\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21677192.svg)](https://doi.org/10.5281/zenodo.21677192)\n[![Modern Go examples](https://github.com/SimonWaldherr/golang-examples/actions/workflows/modern-go.yml/badge.svg)](https://github.com/SimonWaldherr/golang-examples/actions/workflows/modern-go.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n\nSmall, focused programs for learning Go—from `Hello, World!` to concurrency,\nWebAssembly, runtime tracing, and modern language features. Most examples are\nstandalone programs and can be run independently.\n\nUse the [online editor](https://simonwaldherr.github.io/golang-examples/) to\nedit and run examples in the browser, or play the WebAssembly-based\n[Qix game](https://simonwaldherr.github.io/golang-examples/non-std-lib/ebiten.html).\n\n## Quick start\n\nThe module version in [`go.mod`](go.mod) is the source of truth for the\nrequired Go toolchain.\n\n```shell\ngit clone https://github.com/SimonWaldherr/golang-examples.git\ncd golang-examples\ngo run ./beginner/HelloWorld.go\ngo run ./advanced/iterators\n./scripts/check-modern.sh\n```\n\n## Repository map\n\n| Directory | What you will find |\n| --- | --- |\n| [`beginner/`](beginner/) | Syntax, types, control flow, files, and small algorithms |\n| [`advanced/`](advanced/) | Generics, iterators, concurrency, encoding, tests, and benchmarks |\n| [`expert/`](expert/) | Servers, tracing, assembly, CGO, cryptography, and image generation |\n| [`non-std-lib/`](non-std-lib/) | Examples that depend on third-party packages or external services |\n| [`tinygo/`](tinygo/) | TinyGo and microcontroller examples |\n\n## Modern Go highlights\n\nThese examples intentionally use recent stable Go features:\n\n| Go version | Feature | Run it |\n| --- | --- | --- |\n| 1.23 | Range-over-function iterators plus `iter`, `maps`, and `slices` | `go run ./advanced/iterators` |\n| 1.24 | Generic type aliases | `go run ./advanced/generic-alias` |\n| 1.24 | Benchmarks with `testing.B.Loop` | `go test ./advanced/benchmark-loop -bench .` |\n| 1.25 | `sync.WaitGroup.Go` | `go run ./advanced/waitgroup-go` |\n| 1.25 | Deterministic concurrent tests with `testing/synctest` | `go test ./advanced/synctest` |\n| 1.25 | Runtime trace flight recorder | `go run ./expert/flight-recorder` |\n| 1.26 | Initialized pointers with `new(expression)` | `go run ./beginner/initialized-pointer` |\n| 1.21 | Structured JSON logging with `log/slog` | `go run ./advanced/structured-logging` |\n\nThe flight-recorder example writes `flight.trace`; inspect it with\n`go tool trace flight.trace`.\n\n## Featured project: nanoGo\n\n[nanoGo](https://github.com/SimonWaldherr/nanoGo) is a minimalist interpreter\nfor a supported subset of Go. It evaluates source code dynamically in a CLI,\nREPL, embedded host, or browser playground; when used in the browser, the\ninterpreter itself is compiled to WebAssembly. That makes nanoGo a strong fit\nfor interactive tutorials, editable documentation, controlled snippets, and\nbrowser-based Go experiments. Try the\n[nanoGo playground](https://simonwaldherr.github.io/nanoGo/) or embed it in a\nweb page.\n\n### nanoGo, TinyGo, and GopherJS solve different problems\n\n| | [nanoGo](https://github.com/SimonWaldherr/nanoGo) | [TinyGo](https://tinygo.org/) | [GopherJS](https://github.com/gopherjs/gopherjs) |\n| --- | --- | --- | --- |\n| Execution model | Interprets supported Go source at runtime | Compiles Go programs ahead of time | Compiles Go programs ahead of time to JavaScript |\n| Browser artifact | The interpreter runs in WASM and evaluates guest source dynamically | The application itself can be compiled to WASM | Pure JavaScript generated from the application |\n| Best suited to | Playgrounds, REPLs, live examples, controlled embedded scripting, and teaching | Microcontrollers, embedded applications, and deployable WASM programs | Browser front ends and JavaScript-based web integrations |\n| Go compatibility | Deliberately supported language and library subset | A compiler with its own documented Go compatibility differences | Broad Go support with documented browser and JavaScript-runtime constraints |\n| Host control | Optional capabilities and cooperative resource limits can restrict guest source | The compiled program runs for its selected target; TinyGo is not an interpreter sandbox | The generated program executes with normal browser JavaScript capabilities |\n\nnanoGo is therefore not a smaller replacement for TinyGo or GopherJS. Choose\n**nanoGo** when source must be edited or evaluated at runtime; choose\n**TinyGo** when you want to compile and deploy an application, for example to\na Raspberry Pi Pico; choose **GopherJS** when compiled JavaScript is the right\nbrowser target.\n\n### The existing live editor uses GopherJS\n\nThe [GitHub Pages editor](https://simonwaldherr.github.io/golang-examples/)\nuses its [`go2js`](https://github.com/live-codes/go2js) integration, which is\nbased on GopherJS. Pressing \u003ckbd\u003eF5\u003c/kbd\u003e formats the editor contents,\ncompiles the Go program to JavaScript, and evaluates that JavaScript in the\npage. It is a compile-and-run workflow, not a nanoGo interpreter session.\n\n## Related projects\n\nThe following curated list contains public, non-fork repositories from\n[SimonWaldherr](https://github.com/SimonWaldherr) that complement this\ncollection.\n\n### Go learning and reusable tools\n\n- [golang-benchmarks](https://github.com/SimonWaldherr/golang-benchmarks) — examples for measuring Go code\n- [GolangSortingVisualization](https://github.com/SimonWaldherr/GolangSortingVisualization) — visualized sorting algorithms\n- [golibs](https://github.com/SimonWaldherr/golibs) — general-purpose Go packages\n- [gotools](https://github.com/SimonWaldherr/gotools) — a collection of small Go tools\n- [GoRealtimeWeb](https://github.com/SimonWaldherr/GoRealtimeWeb) — real-time web application examples\n- [mdExec](https://github.com/SimonWaldherr/mdExec) — executes code blocks in Markdown files\n\n### Runtimes, data, and AI\n\n- **[nanoGo](https://github.com/SimonWaldherr/nanoGo)** — a Go-subset interpreter for native hosts and WebAssembly, with a playground, REPL, CLI, and embeddable host API\n- [tinySQL](https://github.com/SimonWaldherr/tinySQL) — an educational SQL engine written in pure Go\n- [tinyRAG](https://github.com/SimonWaldherr/tinyRAG) — a lightweight retrieval-augmented generation system\n- [smallR](https://github.com/SimonWaldherr/smallR) — a small R-like environment written in Go\n- [DataDock](https://github.com/SimonWaldherr/DataDock) — a server-side database web interface\n\n### Graphics, games, and hardware\n\n- [golang-minigames](https://github.com/SimonWaldherr/golang-minigames) — small games written in Go\n- [bbmandelbrotGo](https://github.com/SimonWaldherr/bbmandelbrotGo) — Mandelbrot image generation\n- [FluidSimASCII](https://github.com/SimonWaldherr/FluidSimASCII) — an ASCII fluid simulator\n- [vango](https://github.com/SimonWaldherr/vango) — image-manipulation effects\n- [rp2040-examples](https://github.com/SimonWaldherr/rp2040-examples) and [rpi-examples](https://github.com/SimonWaldherr/rpi-examples) — Raspberry Pi and RP2040 examples\n- [RGB-LED-Matrix](https://github.com/SimonWaldherr/RGB-LED-Matrix) and [pico75player](https://github.com/SimonWaldherr/pico75player) — LED-matrix projects\n\n### Other example collections\n\n- [sql-examples](https://github.com/SimonWaldherr/sql-examples)\n- [openscad-examples](https://github.com/SimonWaldherr/openscad-examples)\n- [zig-examples](https://github.com/SimonWaldherr/zig-examples)\n- [cobol-examples](https://github.com/SimonWaldherr/cobol-examples)\n\nAll are published as free and open-source software. Browse the complete\n[Go repository search](https://github.com/search?q=user%3ASimonWaldherr+language%3AGo\u0026type=repositories)\nfor more.\n\n## Install Go\n\n- macOS with Homebrew: `brew install go`\n- Debian/Ubuntu: `sudo apt install golang-go`\n- Other systems: follow the official [Go installation guide](https://go.dev/doc/install)\n\n## Example catalog\n\nThe examples are divided into beginner, advanced, expert, third-party, and\nTinyGo sections. Commands in the catalog below are shown relative to the\ncorresponding directory unless they include a directory prefix.\n\n### Beginner\n\nTo execute a **Golang** program, write ```go run``` at the cli followed by the name of the file.  \nYou also can convert the file to a binary executable program by the command ```go build```.  \nIf you know ```#!```, also known as [Shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)), there is an equivalent for go: ```//usr/bin/env go run $0 $@ ; exit```  \n\nPrint Hello World with comments ([Golang Playground](https://play.golang.org/p/PiUVBrRB9AR))\n\n```Shell\ngo run HelloWorld.go\n```\n\nPrint Hello World with comments (shebang version)\n\n```Shell\n./HelloWorldShebang.go\n```\n\nDeclare variables and print them ([Golang Playground](https://play.golang.org/p/O3_FWH2IQ75))\n\n```Shell\ngo run var.go\n```\n\nVarious ways (and styles) to print variables ([Golang Playground](https://play.golang.org/p/QH05DN_CeJU))\n\n```Shell\ngo run printf.go\n```\n\nIf statement in Golang ([Golang Playground](https://play.golang.org/p/rIpps0zUl1N))\n\n```Shell\ngo run if.go Hello\n```\n\nDeclare array and print its items ([Golang Playground](https://play.golang.org/p/jqseOd76Dqk))\n\n```Shell\ngo run array.go\n```\n\nDeclare your own functions ([Golang Playground](https://play.golang.org/p/9L0-F76gK0D))\n\n```Shell\ngo run function.go\n```\n\nDo something multiple times ([Golang Playground](https://play.golang.org/p/5G3Ek89eKCH))\n\n```Shell\ngo run for.go\n```\n\nRead via cli provided input data ([Golang Playground](https://play.golang.org/p/oUZ97D0Kg-_O))\n\n```Shell\ngo run args.go string string2\n```\n\nRead via cli provided input data ([Golang Playground](https://play.golang.org/p/4IjMGLZBmue))\n\n```Shell\ngo run input.go\n```\n\nOr scan for it ([Golang Playground](https://play.golang.org/p/rZ6clB9Z9Zu))\n\n```Shell\ngo run scan.go\n```\n\nRead named argument input data ([Golang Playground](https://play.golang.org/p/i7BXecoK_wZ))\n\n```Shell\ngo run flag.go\n```\n\nReturn the *working directory* ([Golang Playground](https://play.golang.org/p/Ijx04bm8r8s))\n\n```Shell\ngo run dir.go\n```\n\nReturn the current time/date in various formats ([Golang Playground](https://play.golang.org/p/tPbn_CbHYYw))\n\n```Shell\ngo run time.go\n```\n\nReturn pseudo random integer values ([Golang Playground](https://play.golang.org/p/PapALcxQkpN))\n\n```Shell\ngo run random.go\n```\n\nConcat strings in two different ways ([Golang Playground](https://play.golang.org/p/sBD_-peBzm5))\n\n```Shell\ngo run cat.go\n```\n\nModulo operation finds the remainder of division ([Golang Playground](https://play.golang.org/p/mYcueUHX1XL))\n\n```Shell\ngo run modulo.go\n```\n\nSplit a string by another string and make an array from the result ([Golang Playground](https://play.golang.org/p/VYP9tVMcbPW))\n\n```Shell\ngo run split.go\n```\n\nAn example implementation of the Ackermann function ([Golang Playground](https://play.golang.org/p/OjNgscvZhZT))\n\n```Shell\ngo run ackermann.go\n```\n\nAn example implementation of the Euclidean algorithm ([Golang Playground](https://play.golang.org/p/b1HWeUyk4Uf))\n\n```Shell\ngo run euklid.go\n```\n\nSubmit a function as argument ([Golang Playground](https://play.golang.org/p/fy0_S3J29_2))\n\n```Shell\ngo run functioncallback.go\n```\n\nA function returned by a function ([Golang Playground](https://play.golang.org/p/earjKURMsPp))\n\n```Shell\ngo run functionclosure.go\n```\n\nA function with an unknown amount of inputs (variadic function) ([Golang Playground](https://play.golang.org/p/s4Fvj8voh3Y))\n\n```Shell\ngo run functionvariadic.go\n```\n\nEmpty interface as argument (You Don't Know Type) ([Golang Playground](https://play.golang.org/p/D7OPshRATt_e))\n\n```Shell\ngo run interface.go\n```\n\nExecute Shell/Bash commands and print its output values ([Golang Playground](https://play.golang.org/p/4Z-wLSkPJll))\n\n```Shell\ngo run shell.go\n```\n\nMake structs (objects) which have functions ([Golang Playground](https://play.golang.org/p/t-082xlTu2t))\n\n```Shell\ngo run oop.go\n```\n\nDependency injection for easier testing\n\n```Shell\ncd beginner/di\ngo test\n```\n\nHashing (md5, sha) in go ([Golang Playground](https://play.golang.org/p/fB2Y2MV7zt3))\n\n```Shell\ngo run hashing.go\n```\n\nError handling – creating, returning, wrapping and inspecting errors\n\n```Shell\ngo run error.go\n```\n\nSwitch statement – expression switch, condition switch, type switch and fallthrough\n\n```Shell\ngo run switch.go\n```\n\nType conversions – numeric casts, string/[]byte/[]rune and strconv helpers\n\n```Shell\ngo run typeconv.go\n```\n\n### Advanced\n\nBenchmarking example (using JSON marshal and unmarshal for the sample) ([Golang Playground](https://play.golang.org/p/80Tcnkb301J)) \nFrom the root directory (`$GOPATH/github.com/SimonWaldherr/golang-examples`), run this command:\n\n```Shell\ngo test -bench=. -benchmem advanced/json_bench/main_test.go\n```\n\nMake pipe-able unix applications with os.Stdin ([Golang Playground](https://play.golang.org/p/NqrUOfBmJtt))\n\n```Shell\ngo run pipe.go\n```\n\nAES-GCM encryption example ([Golang Playground](https://play.golang.org/p/ujfs6s5JZ-P))\n\n```Shell\ngo run aesgcm.go\n```\n\nBcrypt hashing example ([Golang Playground](https://play.golang.org/p/9R7oS56Od6H)) \nPlease install package golang.org/x/crypto/bcrypt before run this file by running `go get golang.org/x/crypto/bcrypt`\n\n```Shell\ngo run bcrypt.go\n```\n\nSearch element is exist in arrays or not ([Golang Playground](https://play.golang.org/p/1gVa9Jgk6vg))\n\n```Shell\ngo run in_array.go\n```\n\nCalculate triangles ([Golang Playground](https://play.golang.org/p/l8ehuAWZitv))\n\n```Shell\ngo run pythagoras.go (float|?) (float|?) (float|?)\n```\n\nRead from stdin (but don't wait for the enter key)\n\n```Shell\ngo run getchar.go\n```\n\nWait and sleep ([Golang Playground](https://play.golang.org/p/qGec1g7rTHC))\n\n```Shell\ngo run wait.go\n```\n\nLast in - first out - example (Pop and push in Golang) ([Golang Playground](https://play.golang.org/p/TekltztwUfE))\n\n```Shell\ngo run lifo.go\n```\n\nSplit a string via regular expression and make an array from the result ([Golang Playground](https://play.golang.org/p/sWFDPMyF-wD))\n\n```Shell\ngo run regex.go\n```\n\nMore advanced regex (with time and dates) ([Golang Playground](https://play.golang.org/p/u1SdhFEwRch))\n\n```Shell\ngo run regex2.go\n```\n\nUse my [golibs regex package](https://github.com/SimonWaldherr/golibs#regex-----) and have fun ([Golang Playground](https://play.golang.org/p/1RxtOxL0nQo))\n\n```Shell\ngo run regex3.go\n```\n\nCalculate and print the fibonacci numbers ([Golang Playground](https://play.golang.org/p/BbjQ_ohw0m1))\n\n```Shell\ngo run fibonacci.go\n```\n\nCalculate and print the requested (32th) prime number ([Golang Playground](https://play.golang.org/p/fB25PQlVWu4))\n\n```Shell\ngo run prime.go 32\n```\n\nDo things with numbers, strings and switch-cases ([Golang Playground](https://play.golang.org/p/MvKDvR_wzlQ))\n\n```Shell\ngo run numbers.go\n```\n\nUse a template to create and fill documents (this example uses [LaTeX](https://www.latex-project.org)) ([Golang Playground](https://play.golang.org/p/riy6SU21alH))\n\n```Shell\ngo run template.go\npdflatex -interaction=nonstopmode template_latex.tex\n```\n\nStart a ticker (do things periodically) \n\n```Shell\ngo run ticker.go\n```\n\nDo something in case of a timeout ([Golang Playground](https://play.golang.org/p/Qtu62LaC3-q))\n\n```Shell\ngo run timeout.go\n```\n\nConvert go object to json string ([Golang Playground](https://play.golang.org/p/s1onU7jpP91))\n\n```Shell\ngo run json.go\n```\n\nRun unix/shell commands in go apps\n\n```Shell\ngo run exec.go\n```\n\nCompress by pipe\n\n```Shell\ngo run compress.go\n```\n\nCompress by file\n\n```Shell\ngo run compress2.go\n```\n\nParse CSV ([Golang Playground](https://play.golang.org/p/plVmXW8TB32))\n\n```Shell\ngo run csv.go\n```\n\nConvert CSV to a Markdown table ([Golang Playground](https://play.golang.org/p/HTobb_U9JQt))\n\n```Shell\ngo run csv2md.go\n```\n\nParse a XML string into a Struct with undefined Fields ([Golang Playground](https://play.golang.org/p/6LuNPcaeagS))\n\n```Shell\ngo run xml.go\n```\n\nRun a self killing app\n\n```Shell\ngo run suicide.go\n```\n\nGoCV : hello video\n\n```Shell\ngo run hello_video.go\n```\n\nGoCV : face detection\n\n```Shell\ngo run face_detect.go 0 model/haarcascade_frontalface_default.xml\n```\n\nRun the example for generic ([Golang Playground](https://go.dev/play/p/586EEI0ZAEe))\n\n```Shell\ngo run generic.go\n```\n\nProtect shared state with sync.Mutex and sync.RWMutex\n\n```Shell\ngo run mutex.go\n```\n\nContext cancellation, timeouts, deadlines, and value propagation\n\n```Shell\ngo run context.go\n```\n\nWorker pool – distribute jobs across a fixed number of goroutines\n\n```Shell\ngo run workerpool.go\n```\n\n### Expert\n\nCalculate π with go (leibniz, euler and prime are running until you stop it via CTRL+C)\n\n```Shell\ngo run pi2go.go leibniz\ngo run pi2go.go euler\ngo run pi2go.go prime\n```\n\nCalculate π with go - same as above - but with live output (based on [gcurses](https://godoc.org/github.com/SimonWaldherr/golibs/gcurses))\n\n```Shell\ngo run pi2go-live.go leibniz\ngo run pi2go-live.go euler\ngo run pi2go-live.go prime\n```\n\n\nList files in working directory\n\n```Shell\ngo run explorer.go\n```\n\nrun assembly code from golang\n\n```Shell\ngo run assembly.go\n```\n\nrun C code from golang \n\n```Shell\ngo run cgo.go\n```\n\ngenerate Go code with golang templates\n\n```Shell\ngo run codegen.go\n```\n\nConvert from rgb to hsl ([Golang Playground](https://play.golang.org/p/UuX27PhA0Zx))\n\n```Shell\ngo run color.go\n```\n\nTelnet with Golang\n\n```Shell\ngo run telnet.go\n```\n\nThe smallest Golang http server\n\n```Shell\ngo run httpd.go\n```\n\nSecure Golang http server\n\n```Shell\ngo run httpsd.go\n```\n\nThe smallest Golang http proxy\n\n```Shell\ngo run proxy.go\n```\n\nRead and write cookies\n\n```Shell\ngo run cookies.go\n```\n\nDemonstrate the power of multithreading / parallel computing\nyou have to set GOMAXPROCS to something greater than 1 to see any effect\n\n```Shell\nexport GOMAXPROCS=8\ntime go run parallel.go true\ntime go run parallel.go false\n```\n\nA dynamic amount of channels\n\n```go\ntime go run dynparallel.go 8\n```\n\nRun the compiler and comment each line which contains an error\n\n```Shell\ngo build gocomment.go\n./gocomment go-app.go\n```\n\nConvert a image to a grayscale and to a color inverted image\n\n```Shell\ngo run image.go\n```\n\nGenerate an image with three colored circles (with intersection)\n\n```Shell\ngo run image2.go\n```\n\nGenerate an image representing the Mandelbrot fractal\n\n```Shell\ngo run image3.go\n```\n\nSql (sqlite) Golang example  \nmaybe you also wanna take a look at my [sql-examples](https://github.com/SimonWaldherr/sql-examples)-project\n\n```Shell\ngo run sqlite.go insert test\ngo run sqlite.go select\n```\n\nPublic-key/asymmetric cryptography signing and validating\n\n```Shell\ngo run ppk-crypto.go\n```\n\nCommand Line Arguments Golang Example\nWe can get argument values though command line by specifying the operator '-' with the name of the argument and the value to be set. E.g. -env=qa\n\n```Shell\ngo run command_line_arguments.go\ngo run command_line_arguments.go -env=qa -consumer=true\n```\n\nCron Golang Example\nWe can trigger a function at a particular time through cron \n\n```Shell\ngo run cron.go\n```\n\nMap Golang Example\nHash Map standard functions in golang \n\n```Shell\ngo run map.go\n```\n\nToken-bucket rate limiter – throttle request throughput with burst support\n\n```Shell\ngo run ratelimiter.go\n```\n\n### TinyGo\n\nYou can even use Go on microcontrollers, the keyword here is [TinyGo](https://tinygo.org/), a go compiler specially developed for SBCs and MCUs.  \nThis is distinct from [nanoGo](https://github.com/SimonWaldherr/nanoGo): TinyGo\ncompiles programs for deployment, while nanoGo interprets a supported Go subset\ndynamically for interactive and embedded-host use cases.\nIf you want to blink the LED of your Raspberry Pi Pico, try this: \n\n```Shell\ntinygo build -o firmware.uf2 -target=pico ./tinygo/blink.go\n```\n\nand then upload it to the pico.\n\n## Compile\n\nOne great aspect of Golang is, that you can start go applications via ```go run name.go```, but also compile it to an executable with ```go build name.go```. After that you can start the compiled version which starts much faster.\nIf you start fibonacci.go and the compiled version you will notice, that the last line which contains the execution time doesn't differ much, but if you start it with ```time ./fibonacci 32``` and ```time go run ./fibonacci.go 32``` you will see the difference.\n\n## License\n\nCopyright © 2026 Simon Waldherr\nDual-licensed. See the [LICENSE](https://github.com/SimonWaldherr/golang-examples/blob/master/LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonwaldherr%2Fgolang-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonwaldherr%2Fgolang-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonwaldherr%2Fgolang-examples/lists"}