Normally we would use this method when we only want to put a timeout for a http request only
client := http.Client{
Timeout: 2 * time.Second,
}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
I think the question is when should we be using contexts, if you go to documentation you will find
Package context defines the Context type, which carries deadlines,
cancellation signals, and other request-scoped values across API
boundaries and between processes.
So lets say you have a API that needs to respond in under some time and you need a way to track all go routines it creates and want to signal them all at the same time to stop; this is the use case where it makes sense to use a context and pass it to all the go routines created by one API call and it becomes really easy to know when the context expired and when everyone needs to stop working.
Although The way you do http request will work but it does not make much sense that you create a context that is explicit to a particular request unless lets say your request is run in a goroutine and you need to pass a cancel signal due to some other inputs you received after executing it.
Ideally in most circumstances context is used to scope a chain of requests/ goroutines you need to signal.
You should read this for more clarity of when to use context
https://blog.golang.org/context