A place to keep my go examples.
Table of Contents
- ARCHITECTURES
- BLOCKCHAIN
- WEB SCRAPING
- CGO
- C CODE
- CLIENT/SERVER
- gRPC
- HTTP
- TCP/IP
- CLOUD SERVICE PROVIDERS
- AMAZON WEB SERVICES
- GOOGLE CLOUD PLATFORM
- MICROSOFT AZURE
- CRYPTOGRAPHY
- ASYMMETRIC CRYPTOGRAPHY
- HASHING
- SYMMETRIC CRYPTOGRAPHY
- DATA STRUCTURES AND ALGORITHMS
- DATA STRUCTURES
- ALGORITHMS
- DATABASES
- NON-RELATIONAL
- RELATIONAL
- ERROR HANDLING
- BASIC
- WRAPPING
- SENTINELS
- FUNCTIONS, METHODS AND INTERFACES
- FUNCTIONS
- METHODS
- INTERFACES
- GO RUNTIME
- GOROUTINES
- INTERACT GO RUNTIME
- INTERACT HOST OS
- INPUT/OUTPUT
- IO READER
- IO WRITER
- IN-PROCESS COMMUNICATION
- SHARED MEMORY
- MESSAGE PASSING
- INTER-PROCESS COMMUNICATION (IPC)
- SHARED MEMORY
- MESSAGE PASSING
- IoT
- RASPBERRY PI
- MODULES AND PACKAGES
- LOCAL PACKAGES
- REMOTE PACKAGES
- MY GENERIC GO TEMPLATES
- JEFFS BASIC TEMPLATE
- PROGRAM BASICS
- FLAGS
- LOGGING
- STRUCTS AND TYPES
- STRUCTS
- CONSTRUCTORS
- GENERICS
- TESTING
- UNIT TESTS
- TABLE-DRIVEN TESTS
- BENCHMARKS
- FUZZING
Appendix
Documentation and Reference
- go
- go standard library
- my-go-packages
- my-go-tools
- This repos github webpage built with concourse
-
BLOCKCHAIN
- bitcoin-ledger - Demonstrates a bitcoin ledger in a blockchain using the unspent transaction output model.
- create-bitcoin-address-from-ecdsa-publickey - Create a bitcoin address from your ecdsa public key using the crypto/ecdsa standard package.
- single-node-blockchain-with-REST - A simple single node sha256 blockchain with a REST JSON API (to view (GET) the blockchain and add (POST) a block).
-
WEB SCRAPING
- [web scrape twitter for ???]
-
C CODE
- simple-c-code - A very simple example to show you how to write a c function in go.
- simple-c-code-using-stdio - A c function in go using stdio.h for printf.
-
gRPC
- - Coming soon.
-
HTTP
- - Coming soon.
-
TCP/IP
- - Coming soon.
-
AMAZON WEB SERVICES
- - Coming soon.
-
GOOGLE CLOUD PLATFORM
- - Coming soon.
-
MICROSOFT AZURE
- - Coming soon.
-
ASYMMETRIC CRYPTOGRAPHY (Great for digital signatures (verify sender) and receiving encrypted data)
- - Coming soon.
-
HASHING (Great for getting fingerprints)
- - Coming soon.
-
SYMMETRIC CRYPTOGRAPHY (Using the same key to encrypt and decrypt)
- - Coming soon.
-
DATA STRUCTURES
-
BUILT-IN
-
FROM SCRATCH
- sets - A collection of unique elements built from a map.
- stack - A LIFO (last-in first-out) built from a slice.
- queue - A FIFO (first-in first-out) built from a slice.
- linked-list - A linked-list built from a struct with a pointer to the next node.
- binary-tree - A tree built from a struct with pointers to left/right children.
-
-
ALGORITHMS
-
SEARCHING
- linear-search - Find a value by scanning each element in turn (O(n)).
- binary-search - Find a value in a sorted slice by repeatedly halving the range (O(log n)).
-
SORTING
- bubble-sort - Sort by repeatedly swapping adjacent out-of-order pairs (O(n²)).
- quick-sort - Sort by partitioning around a pivot and recursing (O(n log n) average).
-
-
NON-RELATIONAL
- - Coming soon.
-
RELATIONAL
- - Coming soon.
-
BASIC
- error-simple - Error handling using the errors standard package.
-
WRAPPING
- error-wrapping - Wrapping errors with %w to add context as they propagate up the call stack using the errors standard package.
-
SENTINELS
- error-sentinel - A sentinel is a named error that callers can check for by identity using the errors standard package.
-
FUNCTIONS
- functions - Using functions to calculate the area of a rectangle and circle.
- functions-pointers-arguments - Using functions to resize a rectangle and circle by passing pointers.
-
METHODS
- methods - Using methods to calculate the area of a rectangle and circle.
- methods-pointers-receivers - Using methods to resize a rectangle and circle using pointer receivers.
-
INTERFACES
- interfaces - Using an interface to calculate the area of a rectangle and circle.
- interfaces-pointers-receivers - Using an interface to resize a rectangle and circle using pointer receivers.
-
GOROUTINES
- goroutines-multi-core - Concurrency across multiples cores. You can play around with workers, threads, cpus/cores and nice to find the fastest performance. It will find the total number of prime numbers within a range. Lightweight goroutines are amazing.
- goroutines-waitgroup - Concurrency using a waitgroup (waiting for a collection of goroutines to finish).
- goroutines-worker-pools - Concurrency using worker pools.
-
INTERACT GO RUNTIME
- simple-go-runtime-interactions - A few go runtime interactions using the runtime standard package.
-
INTERACT HOST OS
- simple-external-commands - Run a few os commands using the os/exec standard package.
- simple-os-interactions - A few os interactions using the syscall package.
-
IO READER
- io-reader - Read data (a stream of bytes) from a string, buffer, file, stdin and a pipe to a buffer using the io standard package.
- io-reader-simple - Read data (a stream of bytes) from a buffer to a buffer using the io standard package.
- read-file - Read a file (*os.File) to a buffer.
- read-user-input - Read user input (os.Stdin) to a buffer (using Read method) and string (using Fscan).
-
IO WRITER
- io-writer - Write data (a stream of bytes) to a buffer, file, stdout and a pipe from a buffer using the io standard package.
- io-writer-simple - Write data (a stream of bytes) to a buffer from a buffer using the io standard package.
-
SHARED MEMORY
-
ASYNCHRONOUS
- - Coming soon.
-
SYNCHRONOUS
- pipes-unnamed-simple - A pipe provides a uni-directional communication channel. This is a very simple example of an unnamed pipe.
- pipes-unnamed - This is a more robust example of an unnamed pipe showing multiple reads.
- pipes-unnamed-io - This example of an unnamed pipe connects an io.Writer and io.Reader.
-
-
MESSAGE PASSING
-
ASYNCHRONOUS
- channels-buffered - Buffered channels are uni-directional, asynchronous with no blocking.
-
SYNCHRONOUS
- channels-unbuffered - Unbuffered channels are uni-directional, synchronous with blocking.
-
-
SHARED MEMORY
-
ASYNCHRONOUS
- - Coming soon.
-
SYNCHRONOUS
- pipes-named - Sending data over a named-pipe (FIFO) from one process to another process.
-
-
MESSAGE PASSING
-
OPERATING SYSTEM
-
ASYNCHRONOUS
- message-queues - Coming soon.
- pub-sub-nats-os - Coming soon.
- tcp - Coming soon.
-
SYNCHRONOUS
- grpc-os - Start a grpc server in the go runtime environment using googles grpc package.
-
-
NETWORK
-
ASYNCHRONOUS
- pub-sub-nats-network - Coming soon.
- tcp-ip - Coming soon.
-
SYNCHRONOUS
- grpc-network - Start a grpc server in the go runtime environment using googles grpc package.
- rest - Coming soon.
-
-
-
RASPBERRY PI
- blink-led-raspberry-pi-gpio-periph - GPIO OUTPUT - Blink an LED via a Raspberry Pi GPIO using the periph.io/... packages.
- push-button-raspberry-pi-gpio-periph - GPIO INPUT - Push a button via a Raspberry Pi GPIO using the periph.io/... packages.
- toggle-led-with-button-raspberry-pi-gpio-periph - Toggle an LED with a button push via a Raspberry Pi GPIO using the periph.io/... packages.
-
LOCAL PACKAGES
- module-with-local-package - A go module with a local package.
-
REMOTE PACKAGES
- module-with-remote-package - A go module with a remote (public) package.
-
JEFFS BASIC TEMPLATE
- jeffs-basic-go-template - My generic go template with flags, logging & error handling. A place to see how everything fits together.
-
FLAGS
-
LOGGING
- jeffs-logger - Logging using my github.com/JeffDeCola/my-go-packages/golang/logger which uses the structured logging log/slog standard package.
-
STRUCTS
- structs-basic - Declaring a struct, creating instances and accessing fields.
- structs-nesting-embedding - Nesting and embedding a struct inside another struct, and how field access differs between them.
-
CONSTRUCTORS
- constructor-simple - Constructors are functions that build and return a new instance of a struct, often with defaults.
- constructor-with-error - Expanding on constructor-simple to add a configuration struct and error handling.
-
GENERICS
- generics-function - A generic function uses a type parameter so a and b are the same type, and so is the result - one function for many types instead of copy-pasting.
- generics-type - A generic type uses a type parameter so one definition serves every element type, instead of writing one type per element.
-
UNIT TESTS
- - Coming soon.
-
TABLE-DRIVEN TESTS
- - Coming soon.
-
BENCHMARKS
- - Coming soon.
-
FUZZING
- - Coming soon.
Current as of go 1.26.4.
- archive
- tar
- zip
- bufio
- builtin (documentation-only - where len, make, panic, etc. live)
- bytes
- cmp
- compress
- bzip2
- flate
- gzip
- lzw
- zlib
- container
- heap
- list
- ring
- context
- crypto
- aes - encryptfile tool, decryptfile tool
- ecdsa - create-bitcoin-address-from-ecdsa-publickey
- elliptic - create-bitcoin-address-from-ecdsa-publickey
- hpke
- md5 - md5-hash-file tool
- rand - create-bitcoin-address-from-ecdsa-publickey
- sha256 - create-bitcoin-address-from-ecdsa-publickey, sha256-hash-file tool
- x509 - create-bitcoin-address-from-ecdsa-publickey
- etc...
- database
- sql
- sql-driver
- debug
- buildinfo
- dwarf
- etc...
- embed
- encoding
- errors - error-simple, error-wrapping, error-sentinel
- expvar
- flag - flags
- fmt
- go
- ast
- build
- etc...
- hash
- adler32
- crc32
- crc64
- fnv
- maphash
- html
- template
- image
- color
- color/palette
- draw
- gif
- jpeg
- png
- index
- suffixarray
- io -
io-reader,
io-reader-simple,
io-writer,
io-writer-simple
- fs
- ioutil
- iter
- log
- slog - jeffs-logger
- syslog
- maps
- math
- big
- bits
- cmplx
- rand
- rand/v2
- mime
- multipart
- quotedprintable
- net
- http
- http/cgi
- etc...
- os
- exec - simple-external-commands
- signal
- user
- path
- filepath
- plugin
- reflect - create-bitcoin-address-from-ecdsa-publickey
- regexp (syntax)
- runtime -
simple-go-runtime-interactions
- cgo
- coverage
- etc...
- slices
- sort
- strconv
- strings
- structs
- sync (atomic)
- syscall -
simple-os-interactions
- js
- testing
- cryptotest
- fstest
- iotest
- quick
- slogtest
- synctest
- text
- scanner
- tabwriter
- template
- template/parse
- time
- tzdata
- unicode
- utf16
- utf8
- unique
- unsafe
- weak