interpolate

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2025 License: MIT Imports: 4 Imported by: 0

README

go-interpolate

Go Reference codecov test

A small tool for easy string interpolation in golang.

Usage

Values from map[string]interface{}
import (
  "fmt"
  "github.com/henvo/go-interpolate"
)

func main() {
  m := map[string]interface{}{
    "name": "Bob",
    "message": "You've got mail!"
  }

  fmt.Println(interpolate.FromMap("Hello %{name}! %{message}", m))
}

Will print:

Hello Bob! You've got mail!

Values from url.Values
import (
  "fmt"
  "net/url"
  "github.com/henvo/go-interpolate"
)

func main() {
  m := make(url.Values)
  m.Add("name", "Bob")
  m.Add("message", "You've got mail!")

  fmt.Println(interpolate.FromURLValues("Hello %{name}! %{message}", m))
}

Will print:

Hello Bob! You've got mail!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromMap

func FromMap(s string, m map[string]interface{}) string

FromMap will perform string interpolation on a given string and map with string keys and interface{} value. In order to be able to interpolate variables with values of the given map the keys to the values need to be wrapped with a percentage sign and curly bracketts `%{}`

func FromURLValues

func FromURLValues(s string, values url.Values) string

FromURLValues will perform string interpolation on a given string and url.Values. Important note: only the first value for a given key is used.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL