status/proto/serviceTester.go

57 lines
898 B
Go
Raw Normal View History

2023-09-30 16:15:11 +00:00
package proto
import (
"net/url"
)
func TestServices() []ServiceStatus {
services := []Service{
{
Name: "exozy.me",
Type: "http",
Url: url.URL{Scheme: "https", Host: "exozy.me"},
},
{
Name: "drgns.space",
Type: "http",
Url: url.URL{Scheme: "https", Host: "drgns.space"},
},
{
Name: "port 1234",
Type: "tcp",
Url: url.URL{Scheme: "tcp://", Host: "localhost:1234"},
},
}
results := []ServiceStatus{}
for _, service := range services {
var serviceResult bool
switch service.Type {
case "http":
{
serviceResult = Request(service.Url.String())
break
}
case "tcp":
{
// go includes port in host
serviceResult = CheckTCPOpen(service.Url.Host)
break
}
}
result := ServiceStatus{
Name: service.Name,
Ok: serviceResult,
Status: "",
}
results = append(results, result)
}
return results
}