go-recipes

module
v0.0.0-...-895af31 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2020 License: MIT

README

Collection of Golang Recipes

Go Report Card

I started this project as I was learning Go. Over time, it evolved into a handy reference for anyone to look up Go recipes and design patterns.

Guides

  • Guide - handy guide to Go - the common knowledge, tips, gotchas, etc.
  • Go Module - Go module

Go-related guides and docs:

  • Goenv - guide to using goenv, a version manager for Go.
  • Unicode - a primer on Unicode.

Recipes

Here's a collection of the recipes:

  • Context - recipes on context package.
    • Timeout - timeout using context package.
  • Collection - recipes on Go collections.
    • Array Passing - recipe that highlights that array is passed as a value to a function and what we can do to modify the original array.
    • Map - basic map operations.
    • Slice - basic slice operations.
  • Cookie - a recipe for working with http cookies. Includes a write-up on the architecture of http cookie and its key attributes.
  • Dependency injection - recipes that shows different ways to implementing dependency injection design pattern using vanilla Go and with open source frameworks dig and wire.
  • Ephemeral SQL data model - a recipe implementing a garbage collector that removes expired records in an SQL database in the background.
  • Fake vs mock in unit testing - a recipe that shows the use of fake and mock using the golang/mock (aka Gomock) and testify/mock packages in a Go unit test.
  • File I/O - recipes on file input/output operations.
    • Reader - a recipe that shows the different ways of reading file: incrementally and all-at-once.
    • Writer - a recipe for writing a file
  • gRPC - a simple gRPC server-client setup.
  • Kafka pubsub - a recipe that implements a simple pubsub setup in Kakfa using the ThreeDotsLabs/watermill package.
  • Long polling - a simple long-polling implementation.
  • Microservice - recipes that implement microservice using the go-kit/kit package.
  • MongoDB - recipes for working with MongoDB using the official driver.
    • Basic - basic operations with Mongo.
    • Changestream - recipe using Mongo Changestream.
  • Postgres - recipes on postgres and general SQL operations.
    • ORM - recipes for working with PostgreSQL using 3 popular frameworks: sql, go-xorm/xorm, and jinzhu/gorm packages.
  • Redis - recipes for working with Redis using the mediocregopher/radix driver.
    • Counter - a recipe that implements global atomic counter that showcases basic operations in Redis.
    • Sessions - a recipe that implements ephemeral sessions in Redis by setting up Redis to remove expired content.
    • Authentication - authentication in Redis.
  • Reflection - Go runtime reflection.
    • Deep Equal - recipe on Go (deep) equality operation using the reflect.DeepEqual to compare 2 values.
    • Type check - recipe that explores ways to check the type of value at runtime.
  • Retry - a recipe that implements retry, which can be useful for connecting to a service in the network reliably.
    • No-package - recipe using retry without a third-party framework.
    • Retry - recipe using the flowchartsman/retry package.
  • Scheduler - a recipe that highlights ways to schedule code to be run periodically.
  • Serialization - recipes on serialization.
    • CSV - recipe for csv serialization.
    • JSON - recipe for json serialization.
  • String - strings and characters in Go.
    • Count Iterate - simple recipe that explores how we count and iterate over a string by rune and byte.
    • Unicode - basic unicode representation and usage.
  • Web - recipes for using the web.
    • JWT - a recipe that shows the handling of simple web form submission and a simple JWT-based authentication using the dgrijalva/jwt-go package.
    • HTML template - a recipe that shows server-side web content rendering using the html/template package.
  • Webhook - a simple webhook implementation.

Other somewhat Go-related recipes:

  • Go Docker images - the long-poll recipe also contain an extensive example of building Go application Docker images using various base Docker images ubuntu, alpine, scratch, and distroless.

Credits and Reference

Directories

Path Synopsis
cli
cobra module
cobra-cmd module
viper module
cloud
s3 module
collection
array-passing module
map module
map-basics module
slice module
slice-basics module
sort module
concurrency
waitgroup module
context
timeout/timeout command
cancel module
timeout module
cookie module
dependency-injection
dig module
no-framework module
wire module
di module
enum module
error module
fake-mock module
generics
custom-type module
linked-list module
graphql
client module
grpc module
hello-world module
test module
http
client module
server/cors module
server/form module
server/jwt module
server/nextjs module
server/static module
io
basic-read module
file-reader module
file-writer module
multi-read module
pipe module
kafka-pubsub module
long-poll module
microservice
simple module
mongo
basic module
expiring-data module
simple module
patterns
functional module
inheritance module
postgres
orm-sql module
pubsub
kafka module
qrcode
reader module
random module
redis
auth module
counter module
sessions module
reflect
equality module
merge-fields module
set-value module
typecheck module
regexp module
retry module
no-package module
standard module
serialization
csv module
json/custom module
sql
sqlite module
squirrel module
string
unicode module
system
interrupt module
template
html module
layouts module
testing
helper module
time
parse module
print module
tls
client-mysql module
typecheck module
url
query-params module
validation module
wasm module
web-form module
webhook module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL