Skip to content

Commit

Permalink
using custom error
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Sep 11, 2023
1 parent 3b1e24d commit 4813897
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions net/net.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 4813897

Please sign in to comment.