Tuesday, February 18, 2025
HomeGolangIs it needed to shut request physique - Getting Assist

Is it needed to shut request physique – Getting Assist


Whereas engaged on REST APIs, we often make sure the response physique is closed. Nevertheless, a colleague steered that the request physique also needs to be closed. From what I’ve learn in varied blogs, it appears there’s no have to explicitly shut the request physique because the server routinely handles it.

My questions are:

  1. Is it needed to shut the request physique? If sure:
    a. Who’s liable for closing the request physique — the consumer or the server?
    b. Do we have to explicitly shut the request physique, or is it routinely closed by the consumer/server?

Thanks,
Madhusudan

Sure, you could shut it.
One thing like;

consumer := http.DefaultClient
resp, err := consumer.Do(req)
if err != nil {
    return nil, err
}
defer resp.Physique.Shut()

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments