Horje
custom middleware echo golang Code Example
custom middleware echo golang
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!")
	}
}
custom echo golang middleware
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)
	}
}





Go

Related
custom middleware echo golang authentication Code Example custom middleware echo golang authentication Code Example
golang create folder if not exist Code Example golang create folder if not exist Code Example
how to add a logo to website icon Code Example how to add a logo to website icon Code Example
how to set logo for website Code Example how to set logo for website Code Example
how to reload current scene godot Code Example how to reload current scene godot Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
14