Errors handling in Golang

Go does not have an Exception handling model as most of the main stream languages. However, it uses the error interface type as the return type for any error that is going to be returned from a function or method: type error interface { Error() string } It is an interface type. An error variable represents any value that can describe itself as a string. The most commonly-used error implementation is in the errors package....

March 10, 2016 · 3 min · Svetlin Ralchev

Develop code generation tool for Golang

In my previous blog post, we discussed one of my favourite code generation tools for Go. We found that they can be used to automate our trivial development tasks or even introduce features like generics and queries. Lets explore how to create our own tool. Introduction The Go generate subcommand is a program that scans for special comments in your Go source code. The comment declares a command that should be executed....

October 31, 2015 · 4 min · Svetlin Ralchev

Query data with Golang and LINQ

Query langauges provide a set of features to querying, projecting and retrieving data (usually relational data). But how to introduces these standard, easily-learned patterns for querying data? In this article we will explore Go LINQ packages that bridges the gap between the world of objects and the world of data. LINQ For first time is introduced by Microsoft in their programming language C#. Its purpose is to bridge the gap between query languages such as SQL and programming languages....

October 25, 2015 · 5 min · Svetlin Ralchev

Generics in Golang

In the article we will take the advantage of [generics] even that they are not first citizen in Go. We will explore gen and genny command line tools. Gen Gen is a code generation tool that brings some generic query functions. It uses annotations to add this functionality to any structure. The generated code is part of your package and does not have any external dependencies. This approach avoids any reflection and produces an efficient concrete implementation for any annotated type....

October 18, 2015 · 8 min · Svetlin Ralchev

Reusing source code with Go templates

In one of my previous blog posts, we discovered go generate command line tool. Lets take the next step and evaluate its advanced benefits to generate a source code by using our own templates. We will explore gotemplate command line tool. Overview This command line tool manages package based Go templates using go generate. By default it provides a set of templates that can be used out of the box:...

October 11, 2015 · 3 min · Svetlin Ralchev