Skip to content

Commit cf5004c

Browse files
committed
handle nil ptr issue
Signed-off-by: Andrew Thornton <[email protected]>
1 parent 54d1553 commit cf5004c

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

modules/context/api.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,14 @@ func APIContexter() func(http.Handler) http.Handler {
277277
next.ServeHTTP(ctx.Resp, ctx.Req)
278278

279279
// Handle adding signedUserName to the context for the AccessLogger
280-
username := ctx.Data["SignedUserName"].(string)
281-
identityPtr := ctx.Req.Context().Value(signedUserNameStringPointerKey).(*string)
282-
if identityPtr != nil && username != "" {
283-
*identityPtr = username
280+
usernameInterface := ctx.Data["SignedUserName"]
281+
identityPtrInterface := ctx.Req.Context().Value(signedUserNameStringPointerKey)
282+
if usernameInterface != nil && identityPtrInterface != nil {
283+
username := usernameInterface.(string)
284+
identityPtr := identityPtrInterface.(*string)
285+
if identityPtr != nil && username != "" {
286+
*identityPtr = username
287+
}
284288
}
285289
})
286290
}

modules/context/context.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,15 @@ func Contexter() func(next http.Handler) http.Handler {
772772
next.ServeHTTP(ctx.Resp, ctx.Req)
773773

774774
// Handle adding signedUserName to the context for the AccessLogger
775-
username := ctx.Data["SignedUserName"].(string)
776-
identityPtr := ctx.Req.Context().Value(signedUserNameStringPointerKey).(*string)
777-
if identityPtr != nil && username != "" {
778-
*identityPtr = username
775+
usernameInterface := ctx.Data["SignedUserName"]
776+
identityPtrInterface := ctx.Req.Context().Value(signedUserNameStringPointerKey)
777+
if usernameInterface != nil && identityPtrInterface != nil {
778+
username := usernameInterface.(string)
779+
identityPtr := identityPtrInterface.(*string)
780+
if identityPtr != nil && username != "" {
781+
*identityPtr = username
782+
}
779783
}
780-
781784
})
782785
}
783786
}

0 commit comments

Comments
 (0)