feat: add MergeRoutes

This commit is contained in:
Derrick Hammer 2024-02-17 03:04:27 -05:00
parent 7c330e308e
commit 3b9f4bbe3d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 17 additions and 4 deletions

View File

@ -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 := ""