Skip to content

bug: unsafe type assertion in ZapLogger middleware can panic #39

Description

@deannos

Description

middleware/logger.go:33 does:

reqID, _ := c.Get(CtxRequestID)
logger.L.Info("request", zap.String("request_id", reqID.(string)), ...)

If CtxRequestID is not set in the context for any reason, reqID is nil and reqID.(string) panics. gin.Recovery() would catch it, but only after the response is already broken.

Location

middleware/logger.go:33

Fix

Use c.GetString(CtxRequestID) which returns an empty string safely instead of the bare type assertion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions