2023-01-26 20:58:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-01-28 20:49:07 +00:00
|
|
|
"errors"
|
2023-01-26 20:58:13 +00:00
|
|
|
"io/ioutil"
|
2023-01-28 20:43:07 +00:00
|
|
|
"os"
|
2023-01-26 20:58:13 +00:00
|
|
|
)
|
|
|
|
|
2023-01-26 22:13:44 +00:00
|
|
|
func fileRead(src string) string {
|
2023-01-26 20:58:13 +00:00
|
|
|
content, err := ioutil.ReadFile(src)
|
|
|
|
|
2023-01-28 20:43:07 +00:00
|
|
|
errorPanic(err)
|
2023-01-26 20:58:13 +00:00
|
|
|
|
|
|
|
return string(content)
|
|
|
|
}
|
2023-01-28 20:43:07 +00:00
|
|
|
|
|
|
|
func fileAddLine(input string, filepath string) {
|
2023-01-28 20:49:07 +00:00
|
|
|
_, err := os.Stat(filepath)
|
|
|
|
if errors.Is(err, os.ErrNotExist) {
|
2023-01-28 20:53:09 +00:00
|
|
|
fileCreate(filepath)
|
2023-01-28 20:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var file *os.File
|
|
|
|
file, err = os.OpenFile(filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
2023-01-28 20:43:07 +00:00
|
|
|
errorPanic(err)
|
|
|
|
|
|
|
|
_, err = file.WriteString(input + "\n")
|
|
|
|
errorPanic(err)
|
|
|
|
}
|
2023-01-28 20:53:09 +00:00
|
|
|
|
|
|
|
func fileCreate(filepath string) {
|
2023-01-29 15:13:57 +00:00
|
|
|
if _, err := os.Stat(filepath); err == nil {
|
2023-01-29 15:09:39 +00:00
|
|
|
_, err := os.Create(filepath)
|
|
|
|
errorPanic(err)
|
2023-01-28 20:53:09 +00:00
|
|
|
|
2023-01-29 15:09:39 +00:00
|
|
|
logger("fileCreate : file created -> " + filepath)
|
2023-01-29 15:13:57 +00:00
|
|
|
} else if errors.Is(err, os.ErrNotExist) {
|
2023-01-29 15:09:39 +00:00
|
|
|
logger("fileCreate : file already exists -> " + filepath)
|
2023-01-29 15:13:57 +00:00
|
|
|
} else {
|
|
|
|
logger("fileCreate : unknown -> " + filepath)
|
2023-01-29 15:09:39 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-28 20:53:09 +00:00
|
|
|
|
2023-01-29 15:09:39 +00:00
|
|
|
func fileCreateDir(dirpath string) {
|
2023-01-29 15:13:57 +00:00
|
|
|
if _, err := os.Stat(dirpath); err == nil {
|
2023-01-29 15:09:39 +00:00
|
|
|
err := os.Mkdir(dirpath, 0755)
|
|
|
|
errorPanic(err)
|
|
|
|
logger("fileCreateDir : folder created -> " + dirpath)
|
2023-01-29 15:13:57 +00:00
|
|
|
} else if errors.Is(err, os.ErrNotExist) {
|
2023-01-29 15:09:39 +00:00
|
|
|
logger("fileCreateDir : folder not created -> " + dirpath)
|
2023-01-29 15:13:57 +00:00
|
|
|
} else {
|
|
|
|
logger("fileCreateDir : unknown -> " + dirpath)
|
2023-01-29 15:09:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2023-01-28 20:53:09 +00:00
|
|
|
}
|