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




Go

Related
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
base64 encode golang Code Example base64 encode golang Code Example

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