git clone https://github.com/iamralch/whoami
Advanced Error Handling in Golang
If you have ever written any Golang code you have probably noticed the built-in error type interface. Golang uses error values to indicate an abnormal state. The error type represents any value that can describe itself as a string. Here is the interface’s declaration: type error interface { Error() string } The most commonly-used error implementation is the errors package’s implementation that allows you to instantiate errors by using the following code snippet:...
Network Programming and Proxies in Golang
Have you used any proxy servers in your infrastructure? There are a lot of different scenarios in which you may use a proxy in order to control access to your machines and resources. I am not saying that it’s the best approach but some companies use that. Recently, I have been working on a TCP service that has to connect via SOCK5 proxy server. But before we dig into that, I would like to show what Golang offers for the regular HTTP user....
Working with FTP protocol in Golang
One of the benefits of using Golang is its http package that provides an easy way to build robust REST APIs. Unfortunately, it does not provide out of the box away to build FTP server or connect to FTP server. In this article, we will explore that by demonstrating the usage of two third party packages that allow that. Connecting to FTP server The most robust and broadly used package that provides an FTP client build by Julien....
Golang: Extending reflect.StructTag to support duplicates
Presently, Golang has limited support of reflection comparing to the mainstream languages like C# and JAVA. It’s not intended to match or beat that languages. In practice, we are using StructTag to add some metadata for the defined struct fields. Such an example is json package, where you can customize the field marshaling. In example below, we customize the json representation of User struct fields: type User struct { ID string `json:"id"` Name string `json:"name"` CreatedAt time....
Design Patterns in Golang: Decorator
Introduction The Decorator pattern adds new functionality to an existing object without altering its structure. It is a structural pattern as this pattern acts as a wrapper to existing class. The instanciate a decorator struct which decorates (wraps) the original object and provides additional functionality keeping its methods signature intact. Purpose Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to inheritance for extending functionality. Wrapping a present, putting it in a box, and wrapping the box....