2

I know in Java Springboot, it is possible to call SecurityContext anywhere in the code to get the context.

For example:

SecurityContext context = SecurityContextHolder.getContext();

My question is, is it possible to get the *gin.Context anywhere in the code without having to pass it as a parameter to my function?

blackgreen
  • 34,072
  • 23
  • 111
  • 129

1 Answers1

0

Golang has another package called "context" which does not depend on "gin". You can use context.Background() anywhere in your code:

import (
    "context"
)

...
// sample usage for Mongodb 
// operation which requires context

resp, err := client.collection.InsertOne(
        context.Background(), // here
        ...,
)
...
ABDULLOKH MUKHAMMADJONOV
  • 4,249
  • 3
  • 22
  • 40