added check on Accept request header
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Paul 2022-08-26 20:52:27 +02:00
parent fc4b4cc2e6
commit 3e23f7e872

View File

@ -19,10 +19,15 @@ func (p *Page) GetContent(c echo.Context) (err error) {
// Process returns main webpage or a JSON // Process returns main webpage or a JSON
func (p *Page) Process(c echo.Context, querytype string) (err error) { func (p *Page) Process(c echo.Context, querytype string) (err error) {
p.GetContent(c) p.GetContent(c)
if querytype != "json" { if querytype == "json" {
return c.Render(http.StatusOK, "index.html", p)
}
return c.JSONPretty(http.StatusOK, p.IP, " ") return c.JSONPretty(http.StatusOK, p.IP, " ")
}
if accept, ok := c.Request().Header["Accept"]; ok {
if accept[0] == "*/*" {
return c.JSONPretty(http.StatusOK, p.IP, " ")
}
}
return c.Render(http.StatusOK, "index.html", p)
} }
// Page defines Web page // Page defines Web page