good videos on context :

https://www.youtube.com/watch?v=LSzR0VEraWw

https://www.youtube.com/watch?v=0x_oUlxzw5A

main use of context, is cancellation and cancellation propagation, context are used to cancel the http request, when it is no longer needed or cancelled and it also cancels other depended http request which are linked to it,

it has a root context and children context’s are created from it

it is a convention that the first parameters of a function should be context if it is using one

to create a root context we use context.Background()

Untitled

we can create different children contexts

context with cancel:

ctx := context.Background()

ctx, cancel := context.WithCancel(ctx)

context with time out:

ctx, cancel := context.WithTimeout(ctx, <time>)
defer cancel()

here we need to call the cancel function no matter what because, the timer will be allocated some resources, and we need to free them at the end of the function

context with deadline:

ctx, cancel := context.WithDeadline(ctx, <time>)