initial commit
This commit is contained in:
commit
535c28cf50
3 changed files with 53 additions and 0 deletions
1
.dockerignore
Normal file
1
.dockerignore
Normal file
|
|
@ -0,0 +1 @@
|
|||
.git
|
||||
13
Dockerfile
Normal file
13
Dockerfile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
FROM golang:1.14-alpine3.12
|
||||
|
||||
RUN go get -u github.com/gin-gonic/gin
|
||||
|
||||
WORKDIR /go/src/app
|
||||
|
||||
COPY src .
|
||||
|
||||
RUN go build src/main.go
|
||||
|
||||
RUN rm -rf src
|
||||
|
||||
ENTRYPOINT ["main"]
|
||||
39
src/main.go
Normal file
39
src/main.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
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")
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue