Test a site and store the output
All checks were successful
Build and copy to prod / build-and-copy (push) Successful in 34s
All checks were successful
Build and copy to prod / build-and-copy (push) Successful in 34s
This commit is contained in:
parent
2561f492f9
commit
4df6d17739
7
main.go
7
main.go
@ -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!"))
|
||||||
})
|
})
|
||||||
|
15
ping/ping.go
15
ping/ping.go
@ -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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user