Skip to content

Instantly share code, notes, and snippets.

@rgiaviti
Last active September 8, 2021 18:51
Show Gist options
  • Save rgiaviti/ae9dc950c148521fbe9977bab6ac5815 to your computer and use it in GitHub Desktop.
Save rgiaviti/ae9dc950c148521fbe9977bab6ac5815 to your computer and use it in GitHub Desktop.
String template with GO
package main
import (
"bytes"
"text/template"
)
func main() {
// string template
t := template.Must(template.New("secrets").Parse("Hello, my token is: {{.TOKEN}}"))
// values to be replaces
realValues := map[string]string{"TOKEN": "1223554155DD3228d482AS"}
// buffer for new replaced string
var strBuffer bytes.Buffer
// replace the values
err := t.Execute(&strBuffer, realValues)
if err != nil {
panic(err)
}
// show the string with replaced values
print(strBuffer.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment