How to validate header?

Hi,

I’m a new comers in GO and trying to create an API with echo. So far simple API is working, but I want to validate my API only accept application/json content type.

Actually I already success implementation for this validation, but it’s on every function

 e.GET("/", func(c echo.Context) Errors {
        contentType := c.Request().Header.Get("Content-Type")
        if contentType != "application/json" {
           return c.JSON(http.StatusBadRequest, "incorrect content type")
        }
 }

Can i validate this content type not in every method? In my mind is create my own middleware for this, am i right?

Yes, you need to create a middleware and place in on top of the middleware stack. For reference you can look into https://github.com/labstack/echo/blob/master/middleware/secure.go#L79.

Even I was als searching for this type of confronting suggestions regarding the header.I want to include that if any informations or service is required not only for this but also for accounting,vat,tax,excise,outsourcing of accounting fell free to consult with the most reliable national debtline who are serving their clients and also enterprise for over than a decade with 100% assurance and assistance.