Skip to content

Commit 799ecc7

Browse files
committed
Fix more naked returns
1 parent 84f05db commit 799ecc7

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

upnp.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func Discover() (nat NAT, err error) {
9595
for i := 0; i < 3; i++ {
9696
_, err = socket.WriteToUDP(message, ssdp)
9797
if err != nil {
98-
return
98+
return nil, err
9999
}
100100
var n int
101101
n, _, err = socket.ReadFromUDP(answerBytes)
@@ -124,16 +124,16 @@ func Discover() (nat NAT, err error) {
124124
var serviceURL string
125125
serviceURL, err = getServiceURL(locURL)
126126
if err != nil {
127-
return
127+
return nil, err
128128
}
129129
var serviceIP string = getServiceIP(serviceURL)
130130
var ourIP string
131131
ourIP, err = getOurIP(serviceIP)
132132
if err != nil {
133-
return
133+
return nil, err
134134
}
135135
nat = &upnpNAT{serviceURL: serviceURL, ourIP: ourIP}
136-
return
136+
return nat, nil
137137
}
138138
err = errors.New("UPnP port discovery failed")
139139
return nat, err
@@ -228,7 +228,7 @@ func getOurIP(serviceIP string) (ip string, err error) {
228228
return ip.String(), nil
229229
}
230230
}
231-
return
231+
return nil, err
232232
}
233233

234234
// getServiceURL parses the xml description at the given root url to find the
@@ -251,22 +251,22 @@ func getServiceURL(rootURL string) (url string, err error) {
251251
a := &root.Device
252252
if a.DeviceType != "urn:schemas-upnp-org:device:InternetGatewayDevice:1" {
253253
err = errors.New("no InternetGatewayDevice")
254-
return
254+
return "", err
255255
}
256256
b := getChildDevice(a, "urn:schemas-upnp-org:device:WANDevice:1")
257257
if b == nil {
258258
err = errors.New("no WANDevice")
259-
return
259+
return "", err
260260
}
261261
c := getChildDevice(b, "urn:schemas-upnp-org:device:WANConnectionDevice:1")
262262
if c == nil {
263263
err = errors.New("no WANConnectionDevice")
264-
return
264+
return "", err
265265
}
266266
d := getChildService(c, "urn:schemas-upnp-org:service:WANIPConnection:1")
267267
if d == nil {
268268
err = errors.New("no WANIPConnection")
269-
return
269+
return "", err
270270
}
271271
url = combineURL(rootURL, d.ControlURL)
272272
return url, err
@@ -380,7 +380,7 @@ func (n *upnpNAT) AddPortMapping(protocol string, externalPort, internalPort int
380380

381381
response, err := soapRequest(n.serviceURL, "AddPortMapping", message)
382382
if err != nil {
383-
return
383+
return 0, err
384384
}
385385

386386
// TODO: check response to see if the port was forwarded
@@ -389,7 +389,7 @@ func (n *upnpNAT) AddPortMapping(protocol string, externalPort, internalPort int
389389
// codes here.
390390
mappedExternalPort = externalPort
391391
_ = response
392-
return
392+
return mappedExternalPort, nil
393393
}
394394

395395
// DeletePortMapping implements the NAT interface by removing up a port forwarding
@@ -403,11 +403,11 @@ func (n *upnpNAT) DeletePortMapping(protocol string, externalPort, internalPort
403403

404404
response, err := soapRequest(n.serviceURL, "DeletePortMapping", message)
405405
if err != nil {
406-
return
406+
return err
407407
}
408408

409409
// TODO: check response to see if the port was deleted
410410
// log.Println(message, response)
411411
_ = response
412-
return
412+
return nil
413413
}

0 commit comments

Comments
 (0)