Skip to content

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

License

Notifications You must be signed in to change notification settings

siberia-projects/siberia-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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