forked from voransoy/cngo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cngo.go
36 lines (30 loc) · 811 Bytes
/
cngo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"github.com/gin-gonic/gin"
"log"
"net/http"
)
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{ "status" : "OKAY" })
})
r.GET("/t/:host", testWebsite)
// It detects PORT env
r.Run()
}
func testWebsite(c *gin.Context) {
host := "https://" + c.Param("host")
resp, err := http.Get(host)
if err != nil {
log.Printf("Couldn't test website %s: %v", host, err)
c.JSON(http.StatusInternalServerError, gin.H{"status": "ERROR", "error" : err.Error()})
}
if resp.StatusCode != 200 {
log.Printf("Website %s didin't respond with OK", host)
c.JSON(http.StatusOK, gin.H{"website": host, "status": "FAIL"})
} else {
log.Printf("Website %s is OK", host)
c.JSON(http.StatusOK, gin.H{"website": host, "status": "OK"})
}
}