Goit

Simple and lightweight Git web server
git clone https://git.omkov.net/Goit
git clone [email protected]:Goit
Log | Tree | Refs | README | Download

AuthorJakob Wakeling <[email protected]>
Date2025-02-28 23:50:07
Commitbaf02ae8053952fff2bbd6ecbd50052caf9edeae
Parentdad559f9cef9414fb39d086377ac2cbe989a8bf2
Branch master
Tag 0.2.3

Log before serving HTTP to track possible crash

Diffstat

M src/main.go | 10 +++++-----

1 files changed, 5 insertions, 5 deletions

diff --git a/src/main.go b/src/main.go
index 3709d78..688dfe7 100644
--- a/src/main.go
+++ b/src/main.go
@@ -136,21 +136,21 @@ func main() {
 
 	/* Listen for HTTP on the specified port */
 	if err := http.ListenAndServe(goit.Conf.HTTPAddr+":"+goit.Conf.HTTPPort, h); err != nil {
-		log.Fatalln("[http]", err.Error())
+		util.PrintError(err)
 	}
 }
 
 func logHttp(next http.Handler) http.Handler {
 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-		t1 := time.Now()
-		next.ServeHTTP(w, r)
-
 		ip := r.RemoteAddr
 		if fip := r.Header.Get("X-Forwarded-For"); goit.Conf.IPForwarded && fip != "" {
 			ip = fip
 		}
 
-		log.Println("[http]", r.Method, r.URL.String(), "from", ip, "in", time.Since(t1))
+		t1 := time.Now()
+		log.Println("[HTTP]", r.Method, r.URL.String(), "from", ip, "at", t1.Format("2006-01-02 15:04:05.999999999"))
+		next.ServeHTTP(w, r)
+		log.Println("[HTTP]", r.Method, r.URL.String(), "from", ip, "in", time.Since(t1))
 	})
 }