fehlerbehebung

This commit is contained in:
xoy 2023-01-28 21:49:07 +01:00
parent 0a1846adb8
commit 5ba64e7efb
1 changed files with 9 additions and 1 deletions

10
file.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"errors"
"io/ioutil" "io/ioutil"
"os" "os"
) )
@ -14,7 +15,14 @@ func fileRead(src string) string {
} }
func fileAddLine(input string, filepath string) { func fileAddLine(input string, filepath string) {
file, err := os.OpenFile(filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) _, err := os.Stat(filepath)
if errors.Is(err, os.ErrNotExist) {
_, err = os.Create(filepath)
errorPanic(err)
}
var file *os.File
file, err = os.OpenFile(filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
errorPanic(err) errorPanic(err)
_, err = file.WriteString(input + "\n") _, err = file.WriteString(input + "\n")