MY GO EXAMPLES
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
ARCHITECTURES
-
BLOCKCHAIN
-
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 ???]
CGO
-
C CODE
-
A very simple example to show you how to write a c function in go.
-
A c function in go using stdio.h for printf.
-
CLIENT/SERVER
-
gRPC
- Coming soon.
-
HTTP
- Coming soon.
-
TCP/IP
- Coming soon.
CLOUD SERVICE PROVIDERS
-
AMAZON WEB SERVICES
- Coming soon.
-
GOOGLE CLOUD PLATFORM
- Coming soon.
-
MICROSOFT AZURE
- Coming soon.
CRYPTOGRAPHY
-
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 AND ALGORITHMS
-
DATA STRUCTURES
- Coming soon.
-
ALGORITHMS
-
SEARCHING
- Coming soon.
-
SORTING
- Coming soon.
-
DATABASES
-
NON-RELATIONAL
- Coming soon.
-
RELATIONAL
- Coming soon.
ERROR HANDLING
-
BASIC
-
Error handling using the errors standard package.
-
-
WRAPPING
- Coming soon.
-
SENTINELS
- Coming soon.
FUNCTIONS, METHODS AND INTERFACES
-
FUNCTIONS
-
Using functions to calculate the area of a rectangle and circle.
-
Using functions to calculate the area of a rectangle and circle by passing pointers.
-
-
METHODS
-
Using methods to calculate the area of a rectangle and circle.
-
Using methods to calculate the area of a rectangle and circle by passing pointers.
-
Using methods to calculate the area of a rectangle and circle by passing pointers and using pointer receivers.
-
-
INTERFACES
-
Using an interface to calculate the area of a rectangle and circle.
-
Using an interface to calculate the area of a rectangle and circle by passing pointers.
-
Using an interface to calculate the area of a rectangle and circle by passing pointers and using pointer receivers.
-
Using an interface to calculate and manipulate simple 2D and 3D geometric shapes.
-
GO RUNTIME
-
GOROUTINES
-
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.
-
Concurrency using a waitgroup (waiting for a collection of goroutines to finish).
-
Concurrency using worker pools.
-
-
INTERACT GO RUNTIME
-
simple-go-runtime-interactions
A few go runtime interactions using the runtime standard package.
-
-
INTERACT HOST OS
INPUT/OUTPUT
-
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.
-
Read data (a stream of bytes) from a buffer to a buffer using the io standard package.
-
Read a file (*os.File) to a buffer.
-
Read user input (os.Stdin) to a buffer (using Read method) and string (using Fscan).
-
-
IO WRITER
IN-PROCESS COMMUNICATION
-
SHARED MEMORY
-
ASYNCHRONOUS
- Coming soon.
-
SYNCHRONOUS
-
A pipe provides a uni-directional communication channel. This is a very simple example of an unnamed pipe.
-
This is a more robust example of an unnamed pipe showing multiple reads.
-
This example of an unnamed pipe connects an io.Writer and io.Reader.
-
-
-
MESSAGE PASSING
-
ASYNCHRONOUS
-
Buffered channels are uni-directional, asynchronous with no blocking.
-
-
SYNCHRONOUS
-
Unbuffered channels are uni-directional, synchronous with blocking.
-
-
INTER-PROCESS COMMUNICATION (IPC)
-
SHARED MEMORY
-
ASYNCHRONOUS
- Coming soon.
-
SYNCHRONOUS
-
Sending data over a named-pipe (FIFO) from one process to another process.
-
-
-
MESSAGE PASSING
-
OPERATING SYSTEM
-
ASYNCHRONOUS
-
Coming soon.
-
Coming soon.
-
Coming soon.
-
-
SYNCHRONOUS
Start a grpc server in the go runtime environment using googles grpc package.
-
-
NETWORK
-
ASYNCHRONOUS
-
Coming soon.
-
Coming soon.
-
-
SYNCHRONOUS
-
Start a grpc server in the go runtime environment using googles grpc package.
-
Coming soon.
-
-
-
IoT
-
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.
-
MODULES AND PACKAGES
-
LOCAL PACKAGES
-
A go module with a local package.
-
-
REMOTE PACKAGES
-
A go module with a remote (public) package.
-
MY GENERIC GO TEMPLATES
-
JEFFS BASIC TEMPLATE
-
My generic go template with flags, logging & error handling. A place to see how everything fits together.
-
PROGRAM BASICS
-
FLAGS
-
LOGGING
-
Logging using my github.com/JeffDeCola/my-go-packages/golang/logger which uses the structured logging log/slog standard package.
-
STRUCTS AND TYPES
-
STRUCTS
- Coming soon.
-
CONSTRUCTORS
-
Constructors are functions that build and return a new instance of a struct, often with defaults.
-
Expanding on constructor-simple to add a configuration struct and error handling.
-
-
GENERICS
- Coming soon.
TESTING
-
UNIT TESTS
- Coming soon.
-
TABLE-DRIVEN TESTS
- Coming soon.
-
BENCHMARKS
- Coming soon.
-
FUZZING
- Coming soon.
STANDARD GO PACKAGES
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-example
- 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