Test a site and store the output
Build and copy to prod / build-and-copy (push) Successful in 34s

This commit is contained in:
Lewis Dale committed 2024-05-10 09:02:02 +01:00
1 parent 2561f492f9
commit 4df6d17739
2 files changed
+22

No files matched your search

+15
View File
@@ -2,6 +2,7 @@ package ping
import (
"database/sql"
"net/http"
"lewisdale.dev/oopsie/sites"
)
@@ -58,3 +59,17 @@ const saveQuery = `INSERT INTO ping (site, status) VALUES (?, ?);`
func (p *Ping) Save(db *sql.DB) {
db.Exec(saveQuery, p.Site.Url, p.Status)
}
func SendPing(db *sql.DB, site sites.Site) {
p := Ping{
Site: site,
}
if _, err := http.Get(site.Url); err != nil {
p.Status = Failure
} else {
p.Status = Success
}
p.Save(db)
}