fix logError() & function name changes

This commit is contained in:
uan
2025-08-03 11:08:06 +02:00
parent b219a0f459
commit 949932f9dc

14
main.go
View File

@@ -60,7 +60,7 @@ func get(writer http.ResponseWriter, req *http.Request) {
"-", //identifier (can't get) "-", //identifier (can't get)
getOrDash(req.URL.User.Username()), //username getOrDash(req.URL.User.Username()), //username
time.Now().Format("02/Jan/2006:15:04:05 -0700"), //timestamp time.Now().Format("02/Jan/2006:15:04:05 -0700"), //timestamp
req.Method+" "+req.URL.Path+" "+getHttpString(req.ProtoMajor, req.ProtoMinor), //HTTP version req.Method+" "+req.URL.Path+" "+getHttpVersionString(req.ProtoMajor, req.ProtoMinor), //HTTP version
strconv.Itoa(respStatusCode), //response code strconv.Itoa(respStatusCode), //response code
strconv.Itoa(sentBytes), //# of sent bytes strconv.Itoa(sentBytes), //# of sent bytes
req.Referer(), //Referer req.Referer(), //Referer
@@ -103,27 +103,27 @@ func logAccess(
remoteAddr, identifier, authuser, timestamp, request, status, bytesSent, referer, user_agent, remoteAddr, identifier, authuser, timestamp, request, status, bytesSent, referer, user_agent,
) )
os.Mkdir(_logFolder, os.ModeDir|os.ModePerm) os.Mkdir(_logFolder, os.ModeDir|os.ModePerm)
file, err := os.OpenFile(assureSlash(_logFolder)+PATH_ACCESSLOG, FLAGS_LOG_OPEN, PERMS_LOG_OPEN) file, err := os.OpenFile(ensureSlashSuffix(_logFolder)+PATH_ACCESSLOG, FLAGS_LOG_OPEN, PERMS_LOG_OPEN)
if err != nil { if err != nil {
log.Println("couldn't open log access file at", assureSlash(_logFolder)+PATH_ACCESSLOG) log.Println("couldn't open log access file at", ensureSlashSuffix(_logFolder)+PATH_ACCESSLOG)
} }
defer file.Close() defer file.Close()
file.WriteString(out) file.WriteString(out)
} }
func logError(str string) { func logError(str string) {
file, err := os.OpenFile(assureSlash(_logFolder)+PATH_ERRORLOG, FLAGS_LOG_OPEN, PERMS_LOG_OPEN)
os.Mkdir(_logFolder, os.ModeDir|os.ModePerm) os.Mkdir(_logFolder, os.ModeDir|os.ModePerm)
file, err := os.OpenFile(ensureSlashSuffix(_logFolder)+PATH_ERRORLOG, FLAGS_LOG_OPEN, PERMS_LOG_OPEN)
if err != nil { if err != nil {
log.Println("couldn't open log error file at", assureSlash(_logFolder)+PATH_ERRORLOG) log.Println("couldn't open log error file at", ensureSlashSuffix(_logFolder)+PATH_ERRORLOG)
} }
defer file.Close() defer file.Close()
file.WriteString(str + "\n") file.WriteString(str + "\n")
} }
func getHttpString(major, minor int) string { func getHttpVersionString(major, minor int) string {
return "HTTP/" + strconv.Itoa(major) + "." + strconv.Itoa(minor) return "HTTP/" + strconv.Itoa(major) + "." + strconv.Itoa(minor)
} }
@@ -134,6 +134,6 @@ func getOrDash(str string) string {
return str return str
} }
func assureSlash(str string) string { func ensureSlashSuffix(str string) string {
return strings.TrimSuffix(str, "/") + "/" return strings.TrimSuffix(str, "/") + "/"
} }