From 3b9f4bbe3def3ee490bd8da6c7399d1b8a9528c7 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 17 Feb 2024 03:04:27 -0500 Subject: [PATCH] feat: add MergeRoutes --- api/middleware/middleware.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/api/middleware/middleware.go b/api/middleware/middleware.go index 3036c27..ae18394 100644 --- a/api/middleware/middleware.go +++ b/api/middleware/middleware.go @@ -3,16 +3,17 @@ package middleware import ( "context" "crypto/ed25519" + "net/http" + "slices" + "strconv" + "strings" + "git.lumeweb.com/LumeWeb/portal/account" "git.lumeweb.com/LumeWeb/portal/api/registry" "github.com/golang-jwt/jwt/v5" "github.com/julienschmidt/httprouter" "github.com/spf13/viper" "go.sia.tech/jape" - "net/http" - "slices" - "strconv" - "strings" ) const DEFAULT_AUTH_CONTEXT_KEY = "user_id" @@ -157,6 +158,18 @@ func AuthMiddleware(options AuthMiddlewareOptions) func(http.Handler) http.Handl } } +func MergeRoutes(routes ...map[string]jape.Handler) map[string]jape.Handler { + merged := make(map[string]jape.Handler) + + for _, route := range routes { + for k, v := range route { + merged[k] = v + } + } + + return merged +} + func GetUserFromContext(ctx context.Context, key ...string) uint { realKey := ""