Member-only story

Creating Configurable Environment in Golang — Learning Golang

Izzat Arramsyah
2 min readNov 6, 2020

--

image from google.com

INTRODUCTION

In this article, I want to share one relatively easy way to create configurable database details based on the environment we are using, such as Development or Production. This will certainly make it easier for us to develop when there is more than one environment in use. In this tutorial, we will use an SQL database, and for the database details, we will use JSON files.

PROJECT STRUCTURE

-ProjectSQL
--pkg
--src
--config
--configuration.go
--main.go
--config-dev.json
--config-prod.json

DATABASE CONFIGURATION

First, we will create JSON files that we will use as configuration details for the database. For example, here we will create 2 JSON files.

config-dev.json
config-prod.json

CONFIGURATION

Next, we will create code for configuration that will be used to read or load the JSON files we created earlier based on the environment we are using.

--

--

No responses yet