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,11 +19,16 @@ func (p *Page) GetContent(c echo.Context) (err error) {
// Process returns main webpage or a JSON
func (p *Page) Process(c echo.Context, querytype string) (err error) {
p.GetContent(c)
if querytype != "json" {
return c.Render(http.StatusOK, "index.html", p)
}
if querytype == "json" {
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
type Page struct {