Skip to content

Instantly share code, notes, and snippets.

@acoshift

acoshift/main.go Secret

Created July 6, 2017 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acoshift/0733a578c4010bbe9aa6b7b8f08a3164 to your computer and use it in GitHub Desktop.
Save acoshift/0733a578c4010bbe9aa6b7b8f08a3164 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", checkSite)
http.ListenAndServe(":8080", nil)
}
func checkSite(w http.ResponseWriter, r *http.Request) {
q := r.RequestURI[1:]
req, err := http.NewRequest(http.MethodGet, "http://"+q, nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
resp, err := http.Get("http://" + q)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Fprintf(w, "Site \"%s\" is down.", q)
return
}
fmt.Fprintf(w, "Site \"%s\" is up.", q)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment