For Windows, Linux, MacOS and Docker

Image for post
Image for post
Original Gopher image created by Renee French, used Gopher image created by Maria Letta
  1. part: you are reading it right now
  2. part: improving the service
  3. part: upgrade for web
  4. part: adding SSE
  5. part: simple javascript frontend functionality
  6. part: frontend — backend communication
  7. part: server-side logging
  8. part: run it all in docker
  9. part: adding database container
  10. part: database — service communication

Why would you want to create a service?

With Go programming language you can use the final executable the same way on Windows, Linux and MacOS (by generating proper executable). But you cannot install this executable as a service using standard system tools like sc.exe, systemd or launchd. …


Using Go as a backend

Image for post
Image for post
Original Gopher image created by Renee French, used Gopher image created by Maria Letta

SPA is a short term for Single Page Application. That means, the whole website is loaded only once, and its content is changing dynamically, as user interacts with the page.

The result of this is much better user experience. In case of Javascript, you can use Angular, React, Vue and a lot of other different Javascript frameworks, to make you application running as SPA. But you can also use plain and simple Javascript to make it work.

This article will show you, how to make a simple SPA, using as less as possible Javascript code. You will gain the understanding, how it works, and then you can expand this code into much more broader application. …


With Go backend, sending JSON data

Image for post
Image for post

D3 is a Javascript library for doing graphical magic on data. In the year 2020, it was upgraded to version 6.

And this brings us a little problem. Official examples gallery doesn’t use Javascript, instead it uses special Observable Notebook language. It is not easy, nowadays, to find an up-to-date version 6 examples of D3 charts.

This was the reason for this article. I was not able to find out working example of version 6 calendar heat map so I decided to make one.

Please note, that this work stands on shoulder of other people.

In this article, we will use strategy I learnt in Amelia Wattenberger’s book and we will build on those…


As of January 2021

Image for post
Image for post
Google maps image

Czech Republic, or Czechia, is one of the worst countries in the world, if we talk about Covid-19 death-rate. I live here and I would like to share some statistical data and an internal opinion on “why is that” and why the heading of this article is about our country being the worst.

Data, you can find

Using actual worldometers data, we are now at a very nice 8th place from all 220 measured countries, in deaths per 1 million people. Not bad, right? For a country with population about 11 million people.


With all PGTune settings

Image for post
Image for post

This article can be treated as an expansion of previous bigger database benchmark.

Because PostgreSQL was the winner, it would be interesting to make a comparison running PostgreSQL in Docker versus running PostgreSQL natively. And it would be also interesting to know, if there are differences between fine-tuned database settings, using PGTune.

This benchmark was done on all three major systems, running PostgreSQL natively. And on all of them, running PostgreSQL in Docker.

The goal of this benchmark is not to compare Linux versus Windows versus Mac (but you will get the results). …


Plus MariaDB, Percona and TimescaleDB

Image for post
Image for post

Why should you do database benchmark?

I was a long-term SQL Server user. But it was not my decision to use SQL Server. I was young and had to listen older colleagues. If they said, SQL Server is the best, then it was.

Then I was a long-term MySQL user. But it was not my decision to use MySQL. I was older, but my other colleagues were much more experienced. If they said, MySQL is the best, then it was.

I never searched for any other opinions, because at that time, I was learning. How can I argue with my much more experienced colleagues?

Then I found MariaDB. Then I found Percona. And I asked my much more experienced colleagues something like: “Hey, what are they? Why are they?”. The answer was almost always something like: “MySQL is the best, I know MySQL. Do you suppose to use something else? Do you want to break things?” …


MySQL, MariaDB, PostgreSQL, SQL Server

Image for post
Image for post

There are multiple RDBMS databases on the market. Thanks to Docker, you can run them, very easily, at once. Heck, you can even run multiple instances of the same database at the same time.

The question is, why would you want to even run database in Docker and why even bother running different databases.

Why would you want to run database in Docker?

If you are a developer and not running database in Docker, jump right in. Here are some reasons, that may convince you.

1. Databases in Docker are easy to manipulate

You can start, stop, restart and delete database with a simple command.

2. You can run multiple instances of one database engine at once

You can run multiple instances of the same database, for example MySQL, on different ports, every instance with its own settings. …


With an example of creating database and table directly from Go code

Image for post
Image for post
Original Gopher image created by Renee French, used Gopher image created by Maria Letta
  1. part: creating the service
  2. part: improving the service
  3. part: upgrade for web
  4. part: adding SSE
  5. part: simple javascript frontend functionality
  6. part: frontend — backend communication
  7. part: server-side logging
  8. part: run it all in docker
  9. part: adding database container
  10. part: you are reading it right now

Access database running in Docker

Let’s say you have running two (or more) Docker containers. One of those containers holds running database. And you want to access this database from all of those non-database containers.

This article will show you, how to do it. And it will also show you, how to create database and tables directly from Go code.

Prepare the project

Open up your project again and navigate to database.go file. Add a new constant here: const mediumConfig = “user=postgres password=Medium dbname=medium host=medium_database port=5432 sslmode=disable”. …


Make it work with already running Go container

Image for post
Image for post
Original Gopher image created by Renee French, used Gopher image created by Maria Letta
  1. part: creating the service
  2. part: improving the service
  3. part: upgrade for web
  4. part: adding SSE
  5. part: simple javascript frontend functionality
  6. part: frontend — backend communication
  7. part: server-side logging
  8. part: run it all in docker
  9. part: you are reading it right now
  10. part: database — service communication

Is it a good idea, to run database in Docker?

From the developer point of view… is is the best thing you can do. You can run multiple different databases on multiple ports so you can very easily develop your software against all of them. Running MySQL, MariaDB, PostgreSQL and SQL Server all at once? No problem.

Also… have you ever tried to uninstall SQL Server? I don’t know how about you, but on my machine, there was always something left. Using Docker you can very easily run, start, restart, stop and delete database as you like, and be sure that nothing was left. …


And reduce executable size by ~73% as a bonus

Image for post
Image for post
Original Gopher image created by Renee French, used Gopher image created by Maria Letta
  1. part: creating the service
  2. part: improving the service
  3. part: upgrade for web
  4. part: adding SSE
  5. part: simple javascript frontend functionality
  6. part: frontend — backend communication
  7. part: server-side logging
  8. part: you are reading it right now
  9. part: adding database container
  10. part: database — service communication

Why use Docker at all?

Of course, you can create Go executable for every system and you can run it where-ever you want. That’s true.

By using Docker, you can create a neat deploy system for yourself. And you do not care, what system actually runs on the final machine. You only want the machine to run Docker. You can easily stop and start multiple programs (multiple services if you like this terminology). You can easily change the port for Go web server without changing the Go code itself. …

About

Petr Jahoda

Love programming, math, running and piano

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store