~netlandish/gobwebs

a51b316daff847aef506e773ef02ad9bc1436594 — Peter Sanchez 10 months ago 52c04c2
Adding Middleware to crypto
1 files changed, 12 insertions(+), 0 deletions(-)

M crypto/middleware.go
M crypto/middleware.go => crypto/middleware.go +12 -0
@@ 4,6 4,8 @@ import (
	"context"
	"errors"
	"strings"

	"github.com/labstack/echo/v4"
)

var cryptoCtxKey = &contextKey{"crypto"}


@@ 36,3 38,13 @@ func KWForContext(ctx context.Context) *KeyWallet {
	}
	return kw
}

// Middleware adds global entropy value to the context
func Middleware(entropy string) echo.MiddlewareFunc {
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(c echo.Context) error {
			c.SetRequest(c.Request().WithContext(Context(c.Request().Context(), entropy)))
			return next(c)
		}
	}
}