Skip to content

Instantly share code, notes, and snippets.

@s1moe2
Created March 21, 2021 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s1moe2/4c366e3eeef781035ea43b4e5be19871 to your computer and use it in GitHub Desktop.
Save s1moe2/4c366e3eeef781035ea43b4e5be19871 to your computer and use it in GitHub Desktop.
Replace placeholders in text file with Go
func ReplaceInTemplate(filepath string, origString string, replaceString string) error {
input, err := ioutil.ReadFile(filepath)
if err != nil {
return err
}
output := bytes.Replace(input, []byte(origString), []byte(replaceString), -1)
if err = ioutil.WriteFile(filepath, output, 0666); err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment