adding endpoint /all.js
This commit is contained in:
parent
cb6219d000
commit
a5adaf7e50
8
main.go
8
main.go
|
@ -7,7 +7,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"encoding/json"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
proxyproto "github.com/pires/go-proxyproto"
|
proxyproto "github.com/pires/go-proxyproto"
|
||||||
)
|
)
|
||||||
|
@ -130,6 +130,7 @@ func mainHandler(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
wantsJSON := len(fields) >= 2 && fields[1] == "json"
|
wantsJSON := len(fields) >= 2 && fields[1] == "json"
|
||||||
|
wantsJS := len(fields) >= 2 && fields[1] == "js"
|
||||||
|
|
||||||
switch fields[0] {
|
switch fields[0] {
|
||||||
case "":
|
case "":
|
||||||
|
@ -147,6 +148,10 @@ func mainHandler(c *gin.Context) {
|
||||||
case "all":
|
case "all":
|
||||||
if wantsJSON {
|
if wantsJSON {
|
||||||
c.JSON(200, c.Keys)
|
c.JSON(200, c.Keys)
|
||||||
|
} else if wantsJS {
|
||||||
|
c.Writer.Header().Set("Content-Type", "application/javascript")
|
||||||
|
response, _ := json.Marshal(c.Keys)
|
||||||
|
c.String(200, "ifconfig_io = %v\n", string(response))
|
||||||
} else {
|
} else {
|
||||||
c.String(200, "%v", c.Keys)
|
c.String(200, "%v", c.Keys)
|
||||||
}
|
}
|
||||||
|
@ -190,6 +195,7 @@ func main() {
|
||||||
r.GET(fmt.Sprintf("/%s", route), mainHandler)
|
r.GET(fmt.Sprintf("/%s", route), mainHandler)
|
||||||
r.GET(fmt.Sprintf("/%s.json", route), mainHandler)
|
r.GET(fmt.Sprintf("/%s.json", route), mainHandler)
|
||||||
}
|
}
|
||||||
|
r.GET("/all.js", mainHandler)
|
||||||
r.GET("/", mainHandler)
|
r.GET("/", mainHandler)
|
||||||
|
|
||||||
errc := make(chan error)
|
errc := make(chan error)
|
||||||
|
|
Loading…
Reference in New Issue