- you don’t need to do
filePath := file
- you need to check errors
so, the code should look like this:
func sed(old, new, filePath string) error {
fileData, err := ioutil.ReadFile(filePath)
if err != nil {
return err
}
fileString := string(fileData)
fileString = strings.ReplaceAll(fileString, old, new)
fileData = []byte(fileString)
err = ioutil.WriteFile(filePath, fileData, 0o600)
if err != nil {
return err
}
return nil
}