Move structs to core package

This commit is contained in:
TwinProduction
2019-09-06 20:25:31 -04:00
parent eea38c8618
commit ee479be716
6 changed files with 153 additions and 81 deletions

View File

@ -1,49 +1 @@
package watchdog
import (
"net"
"net/http"
"net/url"
"time"
)
type Request struct {
Url string
}
type Result struct {
HttpStatus int
Hostname string
Ip string
Duration time.Duration
Errors []error
}
func (request *Request) GetIp(result *Result) {
urlObject, err := url.Parse(request.Url)
if err != nil {
result.Errors = append(result.Errors, err)
return
}
result.Hostname = urlObject.Hostname()
ips, err := net.LookupIP(urlObject.Hostname())
if err != nil {
result.Errors = append(result.Errors, err)
return
}
result.Ip = ips[0].String()
}
func (request *Request) GetStatus(result *Result) {
client := &http.Client{
Timeout: time.Second * 10,
}
startTime := time.Now()
response, err := client.Get(request.Url)
if err != nil {
result.Errors = append(result.Errors, err)
return
}
result.Duration = time.Now().Sub(startTime)
result.HttpStatus = response.StatusCode
}