Commit b3620e2c authored by Roshan Patil's avatar Roshan Patil
Browse files

http client singleton instance

parent 1ed69b80
Branches
Tags
1 merge request!68Core dev bto c
Showing with 14 additions and 9 deletions
......@@ -4,23 +4,28 @@ import (
"bytes"
"io/ioutil"
"net/http"
"sync"
"time"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/constantmdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/errormdl"
)
var httpClient *http.Client
var once sync.Once
// GetHTTPClient This method will return the httpClient object with preconfigured settings
func GetHTTPClient() *http.Client {
transport := &http.Transport{
MaxIdleConns: constantmdl.MAXIDLECONNS,
MaxIdleConnsPerHost: constantmdl.MAXIDLECONNSPERHOST,
IdleConnTimeout: constantmdl.IDLECONNTIMEOUT,
}
httpClient := &http.Client{
Transport: transport,
}
once.Do(func() {
transport := &http.Transport{
MaxIdleConns: constantmdl.MAXIDLECONNS,
MaxIdleConnsPerHost: constantmdl.MAXIDLECONNSPERHOST,
IdleConnTimeout: constantmdl.IDLECONNTIMEOUT,
}
httpClient = &http.Client{
Transport: transport,
}
})
return httpClient
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment