diff options
author | Robby Zambito <contact@robbyzambito.me> | 2025-08-06 01:07:04 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2025-08-06 01:07:35 -0400 |
commit | aa67960fd63d73e52719be738f5344aa14db6b84 (patch) | |
tree | 2e8835b10ff36bb7f6367e7659feafb131591cd1 | |
parent | e28a4383d8c33724b90b8a433fe87f2e816652f9 (diff) |
go fmt
-rw-r--r-- | main.go | 42 |
1 files changed, 21 insertions, 21 deletions
@@ -3,8 +3,8 @@ package main import ( "encoding/json" "fmt" - "net/http" "net" + "net/http" "regexp" "strings" "time" @@ -13,10 +13,10 @@ import ( const log_length = 100 type accessLog struct { - ClientAddr string `json:"clientAddr"` - RequestedPath string `json:"requestedPath"` - RequestTime time.Time `json:"requestTime"` - HttpMethod string `json:"httpMethod"` + ClientAddr string `json:"clientAddr"` + RequestedPath string `json:"requestedPath"` + RequestTime time.Time `json:"requestTime"` + HttpMethod string `json:"httpMethod"` } func main() { @@ -28,10 +28,10 @@ func main() { // Define a handler function for the root path http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { jsonData, _ := json.Marshal(accessLog{ - ClientAddr: RedactIP(r.RemoteAddr), + ClientAddr: RedactIP(r.RemoteAddr), RequestedPath: r.URL.Path, - RequestTime: time.Now().UTC(), - HttpMethod: r.Method, + RequestTime: time.Now().UTC(), + HttpMethod: r.Method, }) addRotLog(&logs, &n, fmt.Sprintf("%s", string(jsonData))) // Serve the index.html file from the static directory @@ -67,7 +67,7 @@ func addRotLog(logs *[log_length]string, last *int, value string) { } } else { if *last == log_length { - for i := 0 ; i < log_length-1; i++ { + for i := 0; i < log_length-1; i++ { logs[i] = logs[i+1] } logs[log_length-1] = value @@ -80,17 +80,17 @@ func addRotLog(logs *[log_length]string, last *int, value string) { // RedactIP partially redacts an IP address by replacing the last octet with 'xxx' func RedactIP(input string) string { - ipRegex := `\b(?:\d{1,3}\.){3}\d{1,3}\b` - re := regexp.MustCompile(ipRegex) + ipRegex := `\b(?:\d{1,3}\.){3}\d{1,3}\b` + re := regexp.MustCompile(ipRegex) - return re.ReplaceAllStringFunc(input, func(match string) string { - if ip := net.ParseIP(match); ip != nil { - parts := strings.Split(match, ".") - if len(parts) == 4 { - parts[3] = "XXX" - return strings.Join(parts, ".") - } - } - return match - }) + return re.ReplaceAllStringFunc(input, func(match string) string { + if ip := net.ParseIP(match); ip != nil { + parts := strings.Split(match, ".") + if len(parts) == 4 { + parts[3] = "XXX" + return strings.Join(parts, ".") + } + } + return match + }) } |