context

what is context

  1. one request = one goroutine, and other related goroutines must be coordinated by it.

  2. includes request data, like auth, token

  3. cancel signal

  4. timeout

Best practice

  1. pass as 1st param

  2. don't assign nil, then the tracking is broken.

  3. thread safe, so one ctx can be passed to multiple goroutines.

Last updated

Was this helpful?