mirror of https://github.com/hrfee/jfa-go
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
456 B
24 lines
456 B
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
)
|
|
|
|
// TimeoutHandler recovers from an http timeout.
|
|
type TimeoutHandler func()
|
|
|
|
// NewTimeoutHandler returns a new Timeout handler.
|
|
func NewTimeoutHandler(name, addr string, noFail bool) TimeoutHandler {
|
|
return func() {
|
|
if r := recover(); r != nil {
|
|
out := fmt.Sprintf("Failed to authenticate with %s @ %s: Timed out", name, addr)
|
|
if noFail {
|
|
log.Print(out)
|
|
} else {
|
|
log.Fatalf(out)
|
|
}
|
|
}
|
|
}
|
|
}
|