Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1,388 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MY GO EXAMPLES

jeffdecola.com MIT License Go Reference Go Report Card

A place to keep my go examples.

Table of Contents

Appendix

Documentation and Reference

ARCHITECTURES

CGO

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

    • BUILT-IN

      • arrays - A fixed-length collection of elements of the same type.
      • slices - A flexible dynamically-sized array.
      • maps - An unordered collection of key-value pairs (a hash table).
    • 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).

DATABASES

  • NON-RELATIONAL

    • - Coming soon.
  • RELATIONAL

    • - Coming soon.

ERROR HANDLING

  • BASIC

  • 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, METHODS AND INTERFACES

  • FUNCTIONS

  • 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

GO RUNTIME

INPUT/OUTPUT

  • 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.

IN-PROCESS COMMUNICATION

  • 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

INTER-PROCESS COMMUNICATION (IPC)

  • 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

    • NETWORK

IoT

MODULES AND PACKAGES

MY GENERIC GO TEMPLATES

  • JEFFS BASIC TEMPLATE

    • jeffs-basic-go-template - My generic go template with flags, logging & error handling. A place to see how everything fits together.

PROGRAM BASICS

STRUCTS AND TYPES

  • 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.

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.