Show status from the checker thingy
This commit is contained in:
parent
6845a4e573
commit
21f7080ea2
3 changed files with 12 additions and 10 deletions
|
@ -2,15 +2,15 @@ package proto
|
|||
|
||||
import "net/http"
|
||||
|
||||
func Request(url string) bool {
|
||||
func Request(url string) (bool, string) {
|
||||
req, err := http.Get(url)
|
||||
if err != nil {
|
||||
// `req` could be `nil` so we need this check
|
||||
return false
|
||||
return false, ""
|
||||
}
|
||||
if req.StatusCode != 200 {
|
||||
return false
|
||||
return false, req.Status
|
||||
}
|
||||
|
||||
return true
|
||||
return true, req.Status
|
||||
}
|
||||
|
|
|
@ -27,18 +27,20 @@ func TestServices() []ServiceStatus {
|
|||
|
||||
for _, service := range services {
|
||||
var serviceResult bool
|
||||
// Default N/A
|
||||
var serviceStatus string = "N/A"
|
||||
|
||||
switch service.Type {
|
||||
case "http":
|
||||
{
|
||||
serviceResult = Request(service.Url.String())
|
||||
serviceResult, serviceStatus = Request(service.Url.String())
|
||||
break
|
||||
}
|
||||
|
||||
case "tcp":
|
||||
{
|
||||
// go includes port in host
|
||||
serviceResult = CheckTCPOpen(service.Url.Host)
|
||||
serviceResult, serviceStatus = CheckTCPOpen(service.Url.Host)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +48,7 @@ func TestServices() []ServiceStatus {
|
|||
result := ServiceStatus{
|
||||
Name: service.Name,
|
||||
Ok: serviceResult,
|
||||
Status: "",
|
||||
Status: serviceStatus,
|
||||
}
|
||||
|
||||
results = append(results, result)
|
||||
|
|
|
@ -5,17 +5,17 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func CheckTCPOpen(host string) bool {
|
||||
func CheckTCPOpen(host string) (bool, string) {
|
||||
// Just check if the connection is successful
|
||||
timeout := time.Second
|
||||
conn, err := net.DialTimeout("tcp", host, timeout)
|
||||
|
||||
if err != nil || conn == nil {
|
||||
// If timeout or anything else
|
||||
return false
|
||||
return false, err.Error()
|
||||
}
|
||||
|
||||
defer conn.Close()
|
||||
|
||||
return true
|
||||
return true, "OK"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue