ModifyFile opens file, changes file content by executing `repl` callback function and writes new content.
(path string, repl func(string) string)
| 232 | // ModifyFile opens file, changes file content by executing |
| 233 | // `repl` callback function and writes new content. |
| 234 | func ModifyFile(path string, repl func(string) string) { |
| 235 | raw, err := os.ReadFile(path) |
| 236 | if err != nil { |
| 237 | log.Print(err) |
| 238 | return |
| 239 | } |
| 240 | |
| 241 | content := repl(string(raw)) |
| 242 | |
| 243 | if err := os.WriteFile(path, []byte(content), 0700); err != nil { |
| 244 | log.Print(err) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // CreateFile creates a file with given path and content. |
| 249 | func CreateFile(path string, content string) error { |
no outgoing calls
no test coverage detected