From 6b9731b7f72ed0d1b54b20c333e3d3fbbf989a42 Mon Sep 17 00:00:00 2001 From: Achmad Irianto Eka Putra Date: Mon, 28 Aug 2023 21:04:01 +0700 Subject: [PATCH] fix: type assertion on errors fails on wrapped errors --- proxy/proxy.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index 2948a93..dae3176 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -1,6 +1,7 @@ package proxy import ( + "errors" "io" "log" "net" @@ -119,13 +120,16 @@ func extractClientAddress(clientAddr string, source interface{}) (string, string if host, port, err := net.SplitHostPort(clientAddr); err == nil { clientIP = host clientPort = port - } else if addrErr, ok := err.(*net.AddrError); ok { - switch addrErr.Err { - case "missing port in address": - fallthrough - case "too many colons in address": - clientIP = clientAddr - default: + } else { + var addrErr *net.AddrError + if errors.As(err, &addrErr) { + switch addrErr.Err { + case "missing port in address": + fallthrough + case "too many colons in address": + clientIP = clientAddr + default: + } } } }