fehlerbehebung

This commit is contained in:
xoy 2023-01-28 21:49:07 +01:00
parent 52331b2fa0
commit 481092554b
1 changed files with 9 additions and 1 deletions

10
file.go
View File

@ -1,6 +1,7 @@
package main
import (
"errors"
"io/ioutil"
"os"
)
@ -14,7 +15,14 @@ func fileRead(src string) 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)
_, err = file.WriteString(input + "\n")