fehlerbehebung

This commit is contained in:
xoy 2023-01-29 16:09:39 +01:00
parent b2ee161247
commit 992f39a475
3 changed files with 28 additions and 7 deletions

30
file.go
View File

@ -29,9 +29,31 @@ func fileAddLine(input string, filepath string) {
} }
func fileCreate(filepath string) { func fileCreate(filepath string) {
_, err := os.Create(filepath) if !fileExist(filepath) {
_, err := os.Create(filepath)
errorPanic(err)
errorPanic(err) logger("fileCreate : file created -> " + filepath)
} else {
logger("file created -> " + filepath) 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
} }

View File

@ -3,6 +3,7 @@ package main
import "time" import "time"
func logger(input string) { func logger(input string) {
fileCreateDir("./log")
println("[" + time.Now().Format("15:04:05") + "] " + input) println("[" + time.Now().Format("15:04:05") + "] " + input)
fileAddLine("["+time.Now().Format("15:04:05")+"] "+input, "./log/"+time.Now().Format("2006-02-01")+".log") fileAddLine("["+time.Now().Format("15:04:05")+"] "+input, "./log/"+time.Now().Format("2006-02-01")+".log")
} }
@ -13,6 +14,6 @@ func errorPanic(err error, logBefore ...string) {
logger(log) logger(log)
} }
logger(err.Error()) logger(err.Error())
panic("----------------ERROR----------------") panic("\n----------------ERROR----------------\n")
} }
} }

View File

@ -23,8 +23,6 @@ func main() {
err := http.ListenAndServe(addr, nil) err := http.ListenAndServe(addr, nil)
errorPanic(err) errorPanic(err)
defer logger("----------------END----------------")
} }
func handler() { func handler() {