“middleware custom echo golang” Kode Jawaban

middleware custom 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!")
	}
}
Mubashir01234

Middleware Golang Kustom Golang

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)
	}
}

Glamorous camel

Jawaban yang mirip dengan “middleware custom echo golang”

Pertanyaan yang mirip dengan “middleware custom echo golang”

Lebih banyak jawaban terkait untuk “middleware custom echo golang” di Go

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya