Home

Awesome

Interpolate

Build Status Go Reference Go Report Card

A Go library for parameter expansion (like ${NAME} or $NAME) in strings from environment variables. An implementation of POSIX Parameter Expansion, plus some other basic operations that you'd expect in a shell scripting environment like bash.

Installation

go get github.com/mfridman/interpolate@latest

Usage

package main

import (
  "github.com/mfridman/interpolate"
  "fmt"
)

func main() {
  env := interpolate.NewSliceEnv([]string{
    "NAME=James",
  })

  output, _ := interpolate.Interpolate(env, "Hello... ${NAME} welcome to the ${ANOTHER_VAR:-🏖}")

  fmt.Println(output)
  // Output: Hello... James welcome to the 🏖
}

Supported Expansions

Prior work

This repository is a fork of buildkite/interpolate. I'd like to thank the authors of that library for their work. I've forked it to make some changes that I needed for my own use cases, and to make it easier to maintain. I've also added some tests and documentation.

License

Licensed under MIT license, in LICENSE.