fix: sentry middleware interface conversion

This commit is contained in:
Ferdinand Mütsch 2023-01-02 10:55:57 +01:00
parent c1f1b05fa8
commit cf5a515952
3 changed files with 951 additions and 949 deletions

View File

@ -146,15 +146,12 @@ func initSentry(config sentryConfig, debug bool) {
// returns a user id
func getPrincipal(r *http.Request) string {
type identifiable interface {
Identity() string
}
type principalGetter interface {
GetPrincipal() *identifiable
type principalIdentityGetter interface {
GetPrincipalIdentity() string
}
if p := r.Context().Value("principal"); p != nil {
return (*p.(principalGetter).GetPrincipal()).Identity()
return p.(principalIdentityGetter).GetPrincipalIdentity()
}
return ""
}

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,10 @@ func (c *PrincipalContainer) GetPrincipal() *models.User {
return c.principal
}
func (c *PrincipalContainer) GetPrincipalIdentity() string {
return c.principal.Identity()
}
// This middleware is a bit of a dirty workaround to the fact that a http.Request's context
// does not allow to pass values from an inner to an outer middleware. Calling WithContext() on a
// request shallow-copies the whole request itself and therefore, in a chain of handler1(handler2()),