Skip to content

Commit

Permalink
all: imp code
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Aug 9, 2021
1 parent f940890 commit a61b45d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 36 deletions.
42 changes: 24 additions & 18 deletions netutil/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,14 @@ func SplitHost(hostport string) (host string, err error) {
// Any error returned will have the underlying type of *AddrError.
func ValidateMAC(mac net.HardwareAddr) (err error) {
defer func() {
if err != nil {
err = &AddrError{
Err: err,
Kind: KindMAC,
Addr: mac.String(),
}
if err == nil {
return
}

err = &AddrError{
Err: err,
Kind: KindMAC,
Addr: mac.String(),
}
}()

Expand Down Expand Up @@ -214,12 +216,14 @@ const MaxDomainNameLen = 253
// Any error returned will have the underlying type of *AddrError.
func ValidateDomainNameLabel(label string) (err error) {
defer func() {
if err != nil {
err = &AddrError{
Err: err,
Kind: KindLabel,
Addr: label,
}
if err == nil {
return
}

err = &AddrError{
Err: err,
Kind: KindLabel,
Addr: label,
}
}()

Expand Down Expand Up @@ -270,12 +274,14 @@ func ValidateDomainNameLabel(label string) (err error) {
// Any error returned will have the underlying type of *AddrError.
func ValidateDomainName(name string) (err error) {
defer func() {
if err != nil {
err = &AddrError{
Err: err,
Kind: KindName,
Addr: name,
}
if err == nil {
return
}

err = &AddrError{
Err: err,
Kind: KindName,
Addr: name,
}
}()

Expand Down
14 changes: 8 additions & 6 deletions netutil/hostport.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ type HostPort struct {
// underlying type of *AddrError.
func ParseHostPort(addr string) (hp *HostPort, err error) {
defer func() {
if err != nil {
err = &AddrError{
Err: err,
Kind: KindHostPort,
Addr: addr,
}
if err == nil {
return
}

err = &AddrError{
Err: err,
Kind: KindHostPort,
Addr: addr,
}
}()

Expand Down
14 changes: 8 additions & 6 deletions netutil/ipport.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ func IPPortFromAddr(a net.Addr) (ipp *IPPort) {
// underlying type of *AddrError.
func ParseIPPort(addr string) (ipp *IPPort, err error) {
defer func() {
if err != nil {
err = &AddrError{
Err: err,
Kind: KindIPPort,
Addr: addr,
}
if err == nil {
return
}

err = &AddrError{
Err: err,
Kind: KindIPPort,
Addr: addr,
}
}()

Expand Down
14 changes: 8 additions & 6 deletions netutil/reversed.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ func IPFromReversedAddr(arpa string) (ip net.IP, err error) {
}

defer func() {
if err != nil {
err = &AddrError{
Err: err,
Kind: KindARPA,
Addr: arpa,
}
if err == nil {
return
}

err = &AddrError{
Err: err,
Kind: KindARPA,
Addr: arpa,
}
}()

Expand Down

0 comments on commit a61b45d

Please sign in to comment.