mirror of
https://github.com/taigrr/go-fastping
synced 2025-01-18 05:03:15 -08:00
Fix error handling in AddHandler
Added correct return values so that errors can be handled. Closes #2.
This commit is contained in:
parent
e7d04da2f8
commit
0e0b3516a6
@ -130,14 +130,16 @@ func (p *Pinger) AddHandler(event string, handler interface{}) error {
|
|||||||
case "receive":
|
case "receive":
|
||||||
if hdl, ok := handler.(func(*net.IPAddr, time.Duration)); ok {
|
if hdl, ok := handler.(func(*net.IPAddr, time.Duration)); ok {
|
||||||
p.handlers[event] = hdl
|
p.handlers[event] = hdl
|
||||||
|
return nil
|
||||||
} else {
|
} else {
|
||||||
errors.New(fmt.Sprintf("Receive event handler should be `func(*net.IPAddr, time.Duration)`"))
|
return errors.New(fmt.Sprintf("Receive event handler should be `func(*net.IPAddr, time.Duration)`"))
|
||||||
}
|
}
|
||||||
case "idle":
|
case "idle":
|
||||||
if hdl, ok := handler.(func()); ok {
|
if hdl, ok := handler.(func()); ok {
|
||||||
p.handlers[event] = hdl
|
p.handlers[event] = hdl
|
||||||
|
return nil
|
||||||
} else {
|
} else {
|
||||||
errors.New(fmt.Sprintf("Idle event handler should be `func()`"))
|
return errors.New(fmt.Sprintf("Idle event handler should be `func()`"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors.New(fmt.Sprintf("No such event: %s", event))
|
return errors.New(fmt.Sprintf("No such event: %s", event))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user