From 48138972b9bf8e13fed39acd6acec5163ae68edc Mon Sep 17 00:00:00 2001 From: mzack Date: Mon, 11 Sep 2023 09:38:33 +0200 Subject: [PATCH] using custom error --- net/net.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/net.go b/net/net.go index a3c4eeb..a3ec78b 100644 --- a/net/net.go +++ b/net/net.go @@ -1,6 +1,11 @@ package netutil -import "net" +import ( + "errors" + "net" +) + +var ErrMissingPort = errors.New("missing port") // TryJoinHostPort joins host and port. If port is empty, it returns host and an error. func TryJoinHostPort(host, port string) (string, error) { @@ -9,7 +14,7 @@ func TryJoinHostPort(host, port string) (string, error) { } if port == "" { - return host, &net.AddrError{Err: "missing port", Addr: host} + return host, ErrMissingPort } return net.JoinHostPort(host, port), nil