github.com/rudderlabs/rudder-go-kit@v0.30.0/config/env.go (about)

     1  package config
     2  
     3  // TODO: everything in this file should be either removed or unexported
     4  import (
     5  	"os"
     6  	"strings"
     7  )
     8  
     9  // ConfigKeyToEnv gets the env variable name from a given config key
    10  func ConfigKeyToEnv(envPrefix, s string) string {
    11  	if upperCaseMatch.MatchString(s) {
    12  		return s
    13  	}
    14  	snake := camelCaseMatch.ReplaceAllString(s, "${1}_${2}")
    15  	return envPrefix + "_" + strings.ToUpper(strings.ReplaceAll(snake, ".", "_"))
    16  }
    17  
    18  // getEnv returns the environment value stored in key variable
    19  func getEnv(key, defaultVal string) string {
    20  	if value, exists := os.LookupEnv(key); exists {
    21  		return value
    22  	}
    23  	return defaultVal
    24  }