30 lines
437 B
Go
30 lines
437 B
Go
![]() |
package services
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"net"
|
||
|
)
|
||
|
|
||
|
func TCPDial(msg json.RawMessage) (Check, error) {
|
||
|
var config struct {
|
||
|
Address string `json:"address"`
|
||
|
}
|
||
|
err := json.Unmarshal(msg, &config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
check := func() Status {
|
||
|
conn, err := net.Dial("tcp", config.Address)
|
||
|
if err != nil {
|
||
|
return StatusDown
|
||
|
}
|
||
|
|
||
|
// Ignore errors
|
||
|
_ = conn.Close()
|
||
|
|
||
|
return StatusUp
|
||
|
}
|
||
|
return check, nil
|
||
|
}
|