mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-01 13:02:04 +08:00

* fix: refactor auth package * fix: minor changes * fix: refactor jwt * fix: add tests and address comments * fix: address comments * fix: add uncomitted file * fix: address comments * fix: update tests
37 lines
665 B
Go
37 lines
665 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"go.signoz.io/signoz/pkg/types/authtypes"
|
|
)
|
|
|
|
type Pat struct {
|
|
uuid *authtypes.UUID
|
|
headers []string
|
|
}
|
|
|
|
func NewPat(headers []string) *Pat {
|
|
return &Pat{uuid: authtypes.NewUUID(), headers: headers}
|
|
}
|
|
|
|
func (p *Pat) Wrap(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
var values []string
|
|
for _, header := range p.headers {
|
|
values = append(values, r.Header.Get(header))
|
|
}
|
|
|
|
ctx, err := p.uuid.ContextFromRequest(r.Context(), values...)
|
|
if err != nil {
|
|
next.ServeHTTP(w, r)
|
|
return
|
|
}
|
|
|
|
r = r.WithContext(ctx)
|
|
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
|
|
}
|