Last active
September 8, 2021 18:51
-
-
Save rgiaviti/ae9dc950c148521fbe9977bab6ac5815 to your computer and use it in GitHub Desktop.
String template with GO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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