Add some request logging

This commit is contained in:
Maurizio Porrato 2021-05-16 10:12:38 +01:00
parent d5c2b07e49
commit 0cb42d84ea
Signed by: guru
GPG Key ID: C622977DF024AC24
1 changed files with 11 additions and 4 deletions

View File

@ -4,8 +4,8 @@ import (
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"os"
"regexp"
"strings"
"time"
@ -72,6 +72,7 @@ func info(w http.ResponseWriter, req *http.Request) {
if req.Method != "GET" || req.URL.Path != "/info" {
sendJSONError(w, syncstore.NotImplementedError)
} else {
log.Println("info()")
sendJSONOk(w, serviceInfoResp{
Version: "1.1.13",
Message: "Powered by browsersync",
@ -150,6 +151,7 @@ func bookmarks(w http.ResponseWriter, req *http.Request) {
elements := strings.Split(strings.Trim(req.URL.Path, "/"), "/")
if len(elements) == 1 && req.Method == "POST" {
log.Println("createSync()")
createSync(w, req)
return
}
@ -160,10 +162,12 @@ func bookmarks(w http.ResponseWriter, req *http.Request) {
}
if len(elements) == 2 {
if req.Method == "GET" {
log.Printf("getSync(%s)", syncId)
getSync(syncId, w, req)
return
}
if req.Method == "PUT" {
log.Printf("updateSync(%s)", syncId)
updateSync(syncId, w, req)
return
}
@ -174,6 +178,7 @@ func bookmarks(w http.ResponseWriter, req *http.Request) {
if len(elements) == 3 {
if elements[2] == "lastUpdated" {
if req.Method == "GET" {
log.Printf("getLastUpdated(%s)", syncId)
getLastUpdated(syncId, w, req)
return
}
@ -182,6 +187,7 @@ func bookmarks(w http.ResponseWriter, req *http.Request) {
}
if elements[2] == "version" {
if req.Method == "GET" {
log.Printf("getVersion(%s)", syncId)
getVersion(syncId, w, req)
return
}
@ -219,8 +225,7 @@ func init() {
err = fmt.Errorf("Invalid store driver: "+lstore[0])
}
if err != nil {
fmt.Println(err)
os.Exit(1)
log.Fatalf("store initialization failed: %v", err)
}
store = syncstore.NewStore(storeDrv)
}
@ -230,5 +235,7 @@ func main() {
http.HandleFunc("/bookmarks", bookmarks)
http.HandleFunc("/bookmarks/", bookmarks)
http.ListenAndServe(listen, nil)
log.Println("HTTP server listening on", listen)
err := http.ListenAndServe(listen, nil)
log.Println("HTTP server terminated", err)
}