Golang

Listing interfaces with Go AST for gomock/moq

Testing is an important part of software development. Specifically, mocking is a common approach where the developer implements an interface that “mocks” the behaviour of a concrete implementation. Depending on the complexity of the mocked objects, there are many ways you can approach this problem.

Read more

Protecting API access with JWT

A common use case for APIs is to provide authentication middleware, which will let a client make authorized requests to your APIs. Generally, your client performs some sort of authentication, and a session token is issued. Recently, JWT (JSON Web Tokens) are a popular method of providing a session token with an expire time, which doesn’t require some sort of storage to perform validation.

Read more

Handling HTTP requests with go-chi

RESTful API principles dictate the way applications send and retrieve data from API services. We will be implementing our RESTful API service using HTTP as the transportation mechanism. We will take a look at how to provide this with the Go standard library, and then review the usage with an update to go-chi/chi.

Read more

An argument for value receiver constructors

When it comes to object-oriented programming, there’s so much prior work done before Go, that a lot of newcomers to Go can’t help but to bring some concepts over. One of these concepts are object constructors, for which Go doesn’t have an equivalent.

Read more

Interfaces in Go

Interfaces in Go are a powerful language construct, which allow you to define and use objects of different types under a common umbrella interface. What does that even mean? Imagine a Car, or a Motorbike. Both have a license plate. When we declare an interface with a License() string function, both Car and Motorbike objects will satisfy this interface.

Read more