Skip to content

Instantly share code, notes, and snippets.

@Aphellirus
Created October 16, 2022 20:58
Show Gist options
  • Save Aphellirus/6ebb5623b5d97393b52c42ef869d655c to your computer and use it in GitHub Desktop.
Save Aphellirus/6ebb5623b5d97393b52c42ef869d655c to your computer and use it in GitHub Desktop.
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!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment