No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Go Replacer

It is a simple library that replace strings using callback function and search between Start Text and End Text to do it.


Build Status


  1. You can replace dinamically a MAP of strings inside your string
  2. You can replace using existing functions in Go like os.Getenv and replace any environment variable in your string
  3. You can replace using your own custom functions that search on database, make a HTTP request or something else before replace
  4. One line of code and everything works: goreplacer.*


Example 1:

text := "My name is @|name1|@, your name is @|name2|@ and we are in @|country|@"
data := map[string]string{
    "name1":   "Paulo Coutinho",
    "name2":   "Guest",
    "country": "Brasil",

result := replacer.ReplaceByMapOfString(text, "@|", "|@", data)

// result: My name is Paulo Coutinho, your name is Guest and we are in Brasil

Example 2:

text := "The home var is: ENV{MY_HOME}"
result := replacer.ReplaceByEnvVars(text, "ENV{", "}")

// result: The home var is: /Users/paulo

You can check all examples in "goreplacer_test.go"

Support with donation

Support with donation

Supported By Jetbrains IntelliJ IDEA

alt text

Author WebSite