Skip to main content

Golang

Unlocking Docker's Power With Go: A Developer's Perspective - Part 2

·12 mins
In this blog post we continue our last post for most advanced use cases. We talk about managing docker containers in which we talk about spinning a container, listing, starting, stopping, and removing container. We talk about using docker network. We talk about streaming and retrieving logs from docker container. We also cover docker working with docker volumes using Go. At last, we talk about error handling and best practices.

Unlocking Docker's Power With Go: A Developer's Perspective - Part 1

·11 mins
Introduction to Docker Go SDK # In the introductory section of the blog post, we will provide a comprehensive introduction to the Docker Go SDK, highlighting its purpose, benefits, and relevance in the context of building Docker applications using the Go programming language. Brief explanation of Docker Go SDK and its benefits # The Docker Go SDK, also known as the Docker Engine API for Go, is a powerful toolkit that allows developers to interact with Docker and perform Docker-related operations using the Go programming language. It provides a set of APIs and functions that enable seamless integration with Docker, empowering developers to manage Docker resources, automate tasks, and build Docker-centric applications.

Improving Code Quality with Testify in Go: A Deep Dive into Testing

·13 mins
Introduction # Testify is a popular testing toolkit for the Go programming language. It provides a wide range of assertion functions, test suite support, and mocking capabilities, making it a powerful tool for testing Go applications. Testify aims to simplify the process of writing tests and improve the quality of test coverage in Go applications. Testing is a critical aspect of software development that helps ensure that the software behaves as intended and catches bugs early in the development process. Writing tests can be time-consuming, but it is essential for delivering a reliable and maintainable software system. Testify can help make testing in Go more efficient and effective.

How to Write Classes in Golang

·3 mins
Introduction # I have seen many people coming from Python background struggling with Go. What I have obeserved it they write code that is limited to writing functions and calling them. They never leverage design constructs such as abstraction, encapsulation, inheritance, composition etc. I can understand their pain because I’ve been in the same boat. In today’s post I’ll compare how we write classes in Python vs how we do the same thing in a Go way.

Best Logging Library for Golang

·3 mins
Introduction # I recently conducted a poll in the Go community regarding which logging library they use in their personal or professional project. The results were interesting. In this post I have jotted down the most favorite logging libraries and here is my opinion about them. Poll Results # Here are the poll results which I conducted on r/golang, The Go Programming Language community on Twitter and my LinkedIn following.

Release Dangling Elastic IPs using Lambda and Go SDK

·12 mins
Introduction # Today we are going to do a hands-on on how to kill a dangling EIP or in other words, deallocate an unassigned Elastic IP. But before that, let us know… What is an Elastic IP and why do we need it? # Elastic IPs are simply IP addresses provided by Amazon AWS. These are usually attached to internet gateways such as load balancers, or even EC2 instances. I have been using it with EC2 instances directly for my testing use case.

How to Integrate Swagger UI in Go Backend - Gin Edition

·11 mins
Introduction # Unlike FastAPI, Gin does not have OpenAPI integration built in. With FastAPI when you add a route, documentation is already generated. With Gin, this is not the case. But recently I integrated Swagger UI in one of my Go backends and I wanted to document that process. Prerequisites # An already existing Gin server You might consider Building a Book Store API in Golang With Gin if you are starting from scratch. I’ll be using the same book store and extending over it to integrate Swagger UI.

Building a Book Store API in Golang With Gin

·9 mins
Introduction # Go community believes that we need no framework to develop web services. And I agree with that. When you work without using any framework, you learn the ins and outs of development. But once you learn how things work, you must reside in a community and don’t reinvent the wheel. I have created POCs in Go before and I had to deal with HTTP headers, serializing/deserializing, error handling, database connections, and whatnot. But now I’ve decided to join the Gin community as it is one of the widely accepted in the software development community.

Very Basics of Concurrency in Go

·7 mins
Introduction # I’ve dabbled over many languages in the past. Let it be PHP, Java, Python, C/C++, JavaScript and now Go (some of them I only know the syntax). With the experience of all the languages, when I switched to Go, I had no pain understand slices, struct, interfaces, relatively less pain understanding pointers (I’m still learning). But in non of those languages, I did concurrent programming. Although in my first company I did some concurrent programming using Python threads, but the threads didn’t share any data between them.

Difference Between Handler, Handle and HandlerFunc

·6 mins
Introduction # Are you lost between Handle, HandleFunc, and HandlerFunc? If the answer is yes then this post is for you. To understand these pretty well we need to be familiar with interafces. Although interface is just a keyword, it’s confusing at first when you are switching from Python like language; which does not have a similar keyword.

Benchmarking in Go, with Example

Introduction # From The Zen of Go: If you think it’s slow, first prove it with a benchmark Don’t assume if things are slow. Benchmark it and see if they are really slow. One thing to note here is benchmarking a program is different from profiling a program. Benchmarking is the way we check how fast our algorithm is for a given unit of the program. In benchmarking, we typically see how many iterations can a piece of code can run in a given time.

Top 6 Free Learning Resources I used to Learn Go

·4 mins
The internet is filled with Go learning resources. And I am not going to repeat all the links here. I will list only the resources that I went through. I am a self-taught programmer from start. And have limited knowledge of computer science. Which of course is changing day by day. I had a background in Python before getting into Go. So my recommendations will also be aligned with my experience level.

Optional Parameters Using Option Struct

·5 mins
Introduction # In last post we learned how we can use functional options to pass parameter to our functions. In this post we’ll see an alternative way to do the same thing. I’ll take the same code from the last post to keep things simple. Variadic Functions for Options # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 type Coffee struct { CoffeeBeans bool Sugar bool SteamedMilk bool } func New(opts ...func(Coffee) Coffee) Coffee { coffee := Coffee{CoffeeBeans: true} for _, opt := range opts { coffee = opt(coffee) } return coffee } // WithSugar adds sugar to the coffee. func WithSugar(coffee Coffee) Coffee { coffee.Sugar = true return coffee } // WithSteamedMilk adds steamed milk to the coffee. func WithSteamedMilk(coffee Coffee) Coffee { coffee.SteamedMilk = true return coffee } // Prepare makes a cup of coffee with given items. // Ignore the implementation for now. func (c Coffee) Prepare() string { v := reflect.ValueOf(c) typeOfC := v.Type() var items []string for i := 0; i < v.NumField(); i++ { if v.Field(i).Interface() == true { items = append(items, typeOfC.Field(i).Name) } } return fmt.Sprintf("Preparing coffee with %q:", items) } func main() { s := New(WithSugar) fmt.Println(s.Prepare()) } Here on line 1-5 we define type Coffee (or class if you would like to say). This is the analogy our code is build upon because I like coffee whenever I can.