ctdo.de/file.go

31 lines
518 B
Go

package main
import (
"errors"
"io/ioutil"
"os"
)
func fileRead(src string) string {
content, err := ioutil.ReadFile(src)
errorPanic(err)
return string(content)
}
func fileAddLine(input string, filepath string) {
_, 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")
errorPanic(err)
}