Created
March 21, 2021 16:57
-
-
Save s1moe2/4c366e3eeef781035ea43b4e5be19871 to your computer and use it in GitHub Desktop.
Replace placeholders in text file 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
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