60 lines
1.1 KiB
Go
60 lines
1.1 KiB
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) {
|
|
fileCreate(filepath)
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
func fileCreate(filepath string) {
|
|
if !fileExist(filepath) {
|
|
_, err := os.Create(filepath)
|
|
errorPanic(err)
|
|
|
|
logger("fileCreate : file created -> " + filepath)
|
|
} else {
|
|
logger("fileCreate : file already exists -> " + filepath)
|
|
}
|
|
}
|
|
|
|
func fileCreateDir(dirpath string) {
|
|
if fileExist(dirpath) {
|
|
err := os.Mkdir(dirpath, 0755)
|
|
errorPanic(err)
|
|
logger("fileCreateDir : folder created -> " + dirpath)
|
|
} else {
|
|
logger("fileCreateDir : folder not created -> " + dirpath)
|
|
}
|
|
}
|
|
|
|
func fileExist(filepath string) bool {
|
|
if _, err := os.Stat(filepath); err == nil {
|
|
return true
|
|
} else if errors.Is(err, os.ErrNotExist) {
|
|
return false
|
|
}
|
|
return false
|
|
}
|