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

This commit is contained in:
Lewis Dale 2024-05-10 09:02:02 +01:00
parent 2561f492f9
commit 4df6d17739
2 changed files with 22 additions and 0 deletions

View File

@ -20,6 +20,13 @@ func main() {
site := sites.Site{Name: "Lewisdale.dev", Url: "https://lewisdale.dev"} site := sites.Site{Name: "Lewisdale.dev", Url: "https://lewisdale.dev"}
site.Save(db) site.Save(db)
ping.SendPing(db, site)
failureSite := sites.Site{Name: "Example", Url: "https://notreal.tld"}
failureSite.Save(db)
ping.SendPing(db, failureSite)
http.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("This was a GET request!")) w.Write([]byte("This was a GET request!"))
}) })

View File

@ -2,6 +2,7 @@ package ping
import ( import (
"database/sql" "database/sql"
"net/http"
"lewisdale.dev/oopsie/sites" "lewisdale.dev/oopsie/sites"
) )
@ -58,3 +59,17 @@ const saveQuery = `INSERT INTO ping (site, status) VALUES (?, ?);`
func (p *Ping) Save(db *sql.DB) { func (p *Ping) Save(db *sql.DB) {
db.Exec(saveQuery, p.Site.Url, p.Status) 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)
}