siberia-projects / siberia-env

Siberia-env is a library written on clear go for working with environment variables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Siberia Env

Author Source Code Version Coverage Status

What is it?

Siberia-env is a library written on clear go for working with environment variables

For now the library provides a method to expand all labeled (${ENV_VARIABLE_NAME}) environment variables in a content to their real values

How to download?

john@doe-pc:~$ go get github.com/siberia-projects/siberia-env

How to use?

  • Label places you want to expand in your content with "${}" symbols sequence
  • Provide a name of a variable a value of which you want to extract
  • (Optional) Provide a default value using ":" symbol (could be empty)
  • Call the "env.ExpandEnvIn" method with the content

Examples

my:
  custom:
    properties:
      headers:
        - key: Cache-Control
          value: ${CACHE_CONTROL:no-cache}
        - key: Content-Type
          value: application/json
    package main

    import (
		"github.com/siberia-projects/siberia-env/pkg/env"
		"io"
		"os"
    )

    func main() {
		file, _ := os.Open("path_to_the_yaml_file_above.yaml")
		defer file.Close()

		fileContent, _ := io.ReadAll(file)

		expandedFileContent, _ := env.ExpandEnvIn(fileContent)
		expandedFileContentString := string(expandedFileContent)
		
		println(expandedFileContentString)
    }
my:
  custom:
    properties:
      headers:
        - key: Cache-Control
          value: no-cache
        - key: Content-Type
          value: application/json

About

Siberia-env is a library written on clear go for working with environment variables

License:Apache License 2.0