Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

z3ntl3.com/autoenv

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

z3ntl3.com/autoenv

  • v1.0.0
  • Go
  • Socket score

Version published
Created
Source

AutoEnv

Dynamically interpolate placeholder variables in any config file. Made especially to be a plugin for Viper.

Features
  • Very easy to use
  • Deep interpolation/substitution of variables
  • Works with Viper
  • Elegant
  • Ability to change the left/right delimiters for convenience How?
Installation

go get z3ntl3.com/autoenv

After that

You can just import it in your project and use it.

package main

import "z3ntl3.com/autoenv"

Example

Let's consider the following as a .env file:

NAME="z3ntl3"
DOMAIN="com"

WEBSITE="{NAME}.{DOMAIN}"

And this code:

package main

import (
	"fmt"
	"log"

	"github.com/spf13/viper"
	"z3ntl3.com/autoenv/pkg/autoenv"
)

func main(){
    viper.AddConfigPath("../tests")

	// viper.AutomaticEnv()
	viper.SetConfigName("test")
	viper.SetConfigType("env")

	if err := viper.ReadInConfig(); err != nil {
		log.Fatal(err)
	}

	autoenv.New().Execute() // interpolates all the placeholder variables
	fmt.Println(viper.GetString("WEBSITE")) // see the change
}

Output

WEBSITE="{NAME}.{DOMAIN}" turns into z3ntl3.com.

How to change delimiters

Have this example ENV

NAME="z3ntl3"
DOMAIN="com"

WEBSITE="<NAME>.<DOMAIN>"

And this code:

package main

import (
	"fmt"
	"log"

	"github.com/spf13/viper"
	"z3ntl3.com/autoenv/pkg/autoenv"
)

func main() {
	viper.AddConfigPath("../../tests")

	// viper.AutomaticEnv()
	viper.SetConfigName("test2")
	viper.SetConfigType("env")

	if err := viper.ReadInConfig(); err != nil {
		log.Fatal(err)
	}

	autoenv.New().SetDelim("<", ">").Execute() // interpolates all the placeholder variables with the delims
	fmt.Println(viper.GetString("WEBSITE")) // see the change
}

Output

WEBSITE="<NAME>.<DOMAIN>" turns into z3ntl3.com.

License

GNU GPLv3

FAQs

Package last updated on 14 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc