Created
October 16, 2022 20:58
-
-
Save Aphellirus/6ebb5623b5d97393b52c42ef869d655c to your computer and use it in GitHub Desktop.
Custom Middleware Echo Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment