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

Golang code generation

Programs that produce source code are important elements in software engineering. Since Go 1.4, the language ecosystem includes a command line tool that makes it easier to run such tools. It’s called go generate. It scans for special comments in Go source code that identify general commands to run: //go:generate <subcommand> <arguments> Go generate is not part of go build. It does not do dependency analysis and must be run explicitly before running go build....

October 4, 2015 · 3 min · Svetlin Ralchev

Golang: Working with Gzip and Tar

Gzip Gzip is another file compression format that was created to replace the compress program used in early unix system. It is normally used to compress just single files. Compressed archives are created by packaging collections of files into a single tar archive, and then compressing that archive with gzip. The final .tar.gz or .tgz file is a tarball. Compressing a file Compressing operation is very simple to implement. The package exposes gzip....

September 27, 2015 · 4 min · Svetlin Ralchev

Golang: Working with ZIP archives

Golang has several packages that work with different type of archives. In this post I will show you how to use archive/zip package to compress and uncompress zip archives. Zip is one of the most common file formats. It supports lossless data compression of one ore more files and directories. Extracting You can read the content of zip package by using zip reader. Its File property exposes all files and directories of particular zip package....

September 20, 2015 · 2 min · Svetlin Ralchev

Golang code inspection tools

As a software engineer, you always try to improve the quality of your programs. We are looking for the best software development practices and TDD techniques. "Have no fear of perfection - you'll never reach it." ― Salvador Dalí In this article we will explore different code inspection tools in Go ecosystem. We will increase our code quality and engineering skills by running tools that will do analysis on our code base and report the suspicious parts of it....

September 13, 2015 · 7 min · Svetlin Ralchev