Skip to content

Commit 6f96bc2

Browse files
committed
Also use assertOrLog for the caddy log extraction.
1 parent 19c2578 commit 6f96bc2

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

ngcplogger.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -422,39 +422,39 @@ func (l *nGCPLogger) extractCaddyFromPayload(m map[string]any, entry *logging.En
422422
Header: make(http.Header),
423423
},
424424
}
425-
v := val.(map[string]any)
426-
hr.Request.Method = v["method"].(string)
425+
v := assertOrLog[map[string]any](val)
426+
hr.Request.Method = assertOrLog[string](v["method"])
427427
_, isTLS := v["tls"]
428428
var h = "http"
429429
if isTLS {
430430
h = "https"
431431
}
432432
hr.Request.URL = &url.URL{
433433
Scheme: h,
434-
Host: v["host"].(string),
435-
RawPath: v["uri"].(string),
436-
Path: v["uri"].(string),
434+
Host: assertOrLog[string](v["host"]),
435+
RawPath: assertOrLog[string](v["uri"]),
436+
Path: assertOrLog[string](v["uri"]),
437437
}
438438
if t, ok := m["bytes_read"]; ok {
439-
hr.RequestSize = int64(t.(float64))
439+
hr.RequestSize = int64(assertOrLog[float64](t))
440440
}
441441
if t, ok := m["status"]; ok {
442-
hr.Status = int(t.(float64))
442+
hr.Status = int(assertOrLog[float64](t))
443443
}
444444
if t, ok := m["size"]; ok {
445-
hr.ResponseSize = int64(t.(float64))
445+
hr.ResponseSize = int64(assertOrLog[float64](t))
446446
}
447447
if t, ok := m["duration"]; ok {
448-
hr.Latency = time.Duration(t.(float64) * float64(time.Second))
448+
hr.Latency = time.Duration(assertOrLog[float64](t) * float64(time.Second))
449449
}
450-
hr.Request.Proto = v["proto"].(string)
451-
hr.RemoteIP = v["remote_ip"].(string) + ":" + v["remote_port"].(string)
450+
hr.Request.Proto = assertOrLog[string](v["proto"])
451+
hr.RemoteIP = assertOrLog[string](v["remote_ip"]) + ":" + assertOrLog[string](v["remote_port"])
452452

453453
if t, ok := v["headers"]; ok {
454-
headers := t.(map[string]any)
454+
headers := assertOrLog[map[string]any](t)
455455
for h, v := range headers {
456-
for _, s := range v.([]any) {
457-
hr.Request.Header.Add(h, s.(string))
456+
for _, s := range assertOrLog[[]any](v) {
457+
hr.Request.Header.Add(h, assertOrLog[string](s))
458458
}
459459
}
460460
}

0 commit comments

Comments
 (0)