39 lines
869 B
Go
39 lines
869 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func main() {
|
|
router := gin.Default()
|
|
router.GET("/healthcheck", func(c *gin.Context) {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"message": "ok",
|
|
})
|
|
})
|
|
router.GET("adblock", func(c *gin.Context) {
|
|
var length, host, apiKey, url string
|
|
length = c.DefaultQuery("length", "1800")
|
|
host = os.Getenv("PIHOLE_HOST")
|
|
apiKey = os.Getenv("PIHOLE_API_KEY")
|
|
url = host + "/admin/api.php?disable=" + length + "&auth=" + apiKey
|
|
log.Print(url)
|
|
resp, err := http.Get(url)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
"message": "something went wrong",
|
|
})
|
|
log.Fatalln("Unable to disable pihole")
|
|
}
|
|
log.Print(resp)
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"message": "OK",
|
|
})
|
|
|
|
})
|
|
router.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
|
|
}
|