Custom Middleware Echo Golang

[Solved] Custom Middleware Echo Golang | Go - Code Explorer | yomemimo.com
Question : custom middleware echo golang

Answered by : mubashir-khan

package middlewares
import (	"net/http"	"github.com/labstack/echo/v4"
)
// ServerHeader middleware adds a `Server` header to the response.
func MubashirMiddleware(next echo.HandlerFunc) echo.HandlerFunc {	return func(c echo.Context) error {	if (len(c.Request().Header["Authorization"]) > 0) {	if (c.Request().Header["Authorization"][0] == "secretkey") {	c.Response().Header().Set(echo.HeaderServer, "Echo/3.0")	return next(c)	}	}	return c.JSON(http.StatusForbidden, "You are not authorized!")	}
}

Source : | Last Update : Wed, 02 Feb 22

Question : custom echo golang middleware

Answered by : karan-singh-balaslmoq7lr

e.Use(CustomeMiddleware)
// CustomeMiddleware has the access of request object
// and we can decide if we want to go ahead with the req
func CustomeMiddleware() echo.MiddlewareFunc {	return func(next echo.HandlerFunc) echo.HandlerFunc {	return func(c echo.Context) error {	//do the things	}	return next(c)	}
}

Source : | Last Update : Tue, 14 Sep 21

Answers related to custom middleware echo golang

Code Explorer Popular Question For Go