The Merits of Schema First Design

Schema first API design is an approach to designing APIs (Application Programming Interfaces) that begins with defining the data schema first, before writing any code. This is in contrast to code-first API design, where the code is written first and the schema is derived from the code. In schema first API design, the schema is usually defined using a specific language, such as GraphQL schema language or OpenAPI (formerly known as Swagger) specification.
Read more

Concurrent File processing with Golang

I was recently asked to add concurrency to a file processing program that used filepath.Walk to discover and process files. This is the solution I can up with. Naming The function signature for the Walk func in the standard library is as follows; func Walk(root string, fn WalkFunc) error I called mine; func WalkAsync(path string, fn filepath.WalkFunc) chan error The solution package main import ( "fmt" "os" "path/filepath" ) // args are the arguments that will be sent on a channel and passed to the user specified callback type args struct { path string info os.
Read more

Composition Vs Inheritance

I will be using the world class to mean class, struct, object or any king of data thing that encapsulates functionality. Inheritance acquires functionality from its parent class usually via the extends keyword. This method is modelled off genealogy. Think real life parents and the characteristics that are inherited by their child. In Composition a class acquires its functionality from the classes that it is composed of. Think Frankensteins monster.
Read more

MarshalJSON is not getting called - golang

I had the following struct; type ConditionState struct { Label string value int } For a graphql API I wanted to marshal this down to only the Label value. The value is for backend logic and I did not want to expose this information to the frontend; For example var ConditionStateMint = ConditionState{Label: "MINT", value: 100} I wanted to marshal to; "MINT" So I wrote a custom marshaller by overwriting the MarshalJSON method;
Read more

Fulfilling the Read Closer Interface

I often forget how to fulfill the io.ReadCloser interface. The below snippet creates a ReadCloser who’s contents equal “Hello World!” func main() { reader := ioutil.NopCloser(strings.NewReader("Hello World!")) GiveMeAReader(reader) } func GiveMeAReader(r io.ReadCloser) {} (adsbygoogle = window.adsbygoogle || []).push({});

Creating a scheduled Lambda with SAM

In this project we are going to using a Cloud Formation template to orchestrate a AWS::Event::Rule that triggers a lambda execution role, that runs a lambda function every minute. Scaffolding our project You will need sam installed on your computer. We will be using sam to create our project. We will do this by running sam init. You will be presented with an interactive terminal. I aim to make this post language agnostic but I chose the hello world template, using the go1.
Read more

TLS Config in Golang

Below is an example of how to generate a private key, private key, and the root CA certificate. Let us become a CA (Certificate Authority) by creating our CA private key, called rootCA.key openssl genrsa -des3 -out rootCA.key 2048 Now using that private key we can create our Root CA Certificate called rootCA.pem openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1825 -out rootCA.pem Let us now create the keys for our client (we will be using the rootCA above to generate these)
Read more

A Few Notes on Go Versioning

Go follows semantic versioning, and on top of that makes a few assumptions based on which version you are on. Semantic Versioning (SemVer) Refresh Semantic Versioning looks like MAJOR.MINOR.PATCH. Eg 1.10.8 , or 2.12.8 Major patch signals a breaking change. For example if you have a package on 1.2.3 and you upgrade to 2.0.0. This signals that the API has changed from major version 1 => 2. You will have to update the way that you are using the package.
Read more

Setting Up Dynamodb For Local Development

The finished project will be a go binary that will live in an AWS EC2 instance and speak to Dynamodb. I will be running my end to end tests locally and for this I want my code to speak to a locally running instance of Dynamodb; instead of speaking to AWS servers. I will accomplish this by using the amazon/dynamodb-local docker image. My application code will live in a scratch image, and will call into the amazon/dynamodb-local container.
Read more

Laravel Middleware and Dependency Injection

TLDR; In Laravel, middleware is bound in a way that you may not access their constructor. The best way I have found is to bind whatever the input you want, to the DI container and add it a parameter to the middlewares __construct() method. The Scenario Disclaimer: This is not the way to do auth. I have created this scenario to closely resemble a situation I came across in real life.
Read more