use plain pkg module
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
committed by
Florian Schade
parent
259cbc2e56
commit
b07b5a1149
@@ -0,0 +1,31 @@
|
||||
package checks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/opencloud-eu/opencloud/pkg/handlers"
|
||||
)
|
||||
|
||||
// NewTCPCheck returns a check that connects to a given tcp endpoint.
|
||||
func NewTCPCheck(address string) func(context.Context) error {
|
||||
return func(_ context.Context) error {
|
||||
address, err := handlers.FailSaveAddress(address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
conn, err := net.DialTimeout("tcp", address, 3*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = conn.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user