env2js

command module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 11 Imported by: 0

README

env2js

GitHub Release go.mod LICENSE Build Status Codecov

env2js is a tool that will transfer environment variable to a Javascript configuration file.

This is especially useful within virtual machines environments like Docker, where you want to modify the configuration based on the container environment variables.

How it works :

Given the config.js file :

const AppSettings = {
  isServed: true,
  API: {
    apiRoot: "url/server/app",
  },
}

and the environment variables : AppSettings_API_apiRoot="custom/url/app"

After env2js usage, config.js equals :

const AppSettings = {
  isServed: true,
  API: {
    apiRoot: "custom/url/app",
  },
}

Start developing :

1) Install the dependencies :

go mod tidy

ℹ More informations about : go mod tidy

2) Define the three required environment variables :

SETTINGS_FOLDER_PATH : Folder that includes the configuration files

SETTINGS_FILE_PREFIX : File name without the extension, eg : "example.js"

SETTINGS_VARIABLE_NAME : Key name to read inside the file

export SETTINGS_FOLDER_PATH=/path/to/my/config

export SETTINGS_FILE_PREFIX=example

export SETTINGS_VARIABLE_NAME=AppSettings

3) Run the program :

go run .

ℹ More informations about : go run

Environment variables format

  • String : AppSettings_myValue="MyValue"
  • Int : AppSettings_myInt=10
  • Boolean : AppSettings_myBool=true
  • Array index : AppSettings_MyArray_[0]="MyValue"
  • Nested value : AppSettings_MyObject_MyValue="MyValue"

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL