Skip to content

I'm doubtful about app_context #4

@ccoVeille

Description

@ccoVeille

You are embedding a context which is an anti pattern.

Here is the containedctx linter available in golangci-lint

https://github.com/sivchari/containedctx

You can look at the blog post it mentions.

As you are only using ctx.WithValue

I would expect your code to do not define AppContext, and add method to it, but define your app signatures like this

func GetUserID(ctx context.Context) (string, bool)

func SetUserID(ctx context. Context, userID string) context. Context

instead of

func (sc *AppContext) UserID() (string, bool) 

func (sc *AppContext) SetUserID(userID string) AppContext

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