A place to keep my go examples.
MIT License
A place to keep my go examples.
Table of Contents
Documentation and Reference
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
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.
gRPC
HTTP
TCP/IP
GOOGLE CLOUD PLATFORM
MICROSOFT AZURE
ERROR REPORTING
Error Handling using the standard error
package.
FLAGS
The standard flag
package makes it easy to implement command-line flag parsing.
LOGGING
Logging using logrus
package.
MY GENERIC GO TEMPLATE
A simple go template with flags, logging & error handling.
TESTING
ASYMMETRIC CRYPTOGRAPHY (Great for digital signatures (verify sender) and receiving encrypted data)
HASHING (Great for getting fingerprints)
SYMMETRIC CRYPTOGRAPHY (Using the same key to encrypt and decrypt)
NON-RELATIONAL
RELATIONAL
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 ROUTINES
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.
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
package.
INTERACT HOST OS
Run a few os commands using the exec
package.
A few os interactions using the syscall
package.
IO READER
Read data (a stream of bytes) from a string, buffer, file, stdin and
a pipe to a buffer using the standard io
package.
Read data (a stream of bytes) from a buffer to a buffer
using the standard io
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
Write data (a stream of bytes) to a buffer, file, stdout and a pipe
from a buffer using the standard io
package.
Write data (a stream of bytes) to a buffer
from a buffer using the standard io
package.
SHARED MEMORY
ASYNCHRONOUS
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.
SHARED MEMORY
ASYNCHRONOUS
SYNCHRONOUS
Sending data over a named-pipe (FIFO) from one process to another process.
MESSAGE PASSING
OPERATING SYSTEM
ASYNCHRONOUS
tbd.
tbd.
tbd.
SYNCHRONOUS
tbd.
NETWORK
ASYNCHRONOUS
tbd.
tbd.
SYNCHRONOUS
tbd.
tbd.
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
A go module with a local package.
REMOTE PACKAGES
A go module with a remote (public) package.