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 ( ...@@ -4,23 +4,28 @@ import (
"bytes" "bytes"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"sync"
"time" "time"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/constantmdl" "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/constantmdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/errormdl" "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 // GetHTTPClient This method will return the httpClient object with preconfigured settings
func GetHTTPClient() *http.Client { func GetHTTPClient() *http.Client {
once.Do(func() {
transport := &http.Transport{ transport := &http.Transport{
MaxIdleConns: constantmdl.MAXIDLECONNS, MaxIdleConns: constantmdl.MAXIDLECONNS,
MaxIdleConnsPerHost: constantmdl.MAXIDLECONNSPERHOST, MaxIdleConnsPerHost: constantmdl.MAXIDLECONNSPERHOST,
IdleConnTimeout: constantmdl.IDLECONNTIMEOUT, IdleConnTimeout: constantmdl.IDLECONNTIMEOUT,
} }
httpClient := &http.Client{ httpClient = &http.Client{
Transport: transport, Transport: transport,
} }
})
return httpClient 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