reusing connections
This commit is contained in:
parent
e9178b1d09
commit
6b8d6a3bef
27
retrieve.go
27
retrieve.go
@ -79,6 +79,23 @@ func requestConn() {
|
||||
}
|
||||
}
|
||||
|
||||
func GetHTTPSession(endpoint string) (RunningInstance) {
|
||||
ri_mutex.Lock()
|
||||
o, exist := runninginstances[endpoint]
|
||||
ri_mutex.Unlock()
|
||||
if exist == false {
|
||||
o := RunningInstance{}
|
||||
new_client := http.Client{}
|
||||
o.client = new_client
|
||||
o.Status = KEEPALIVE
|
||||
ri_mutex.Lock()
|
||||
runninginstances[endpoint] = o
|
||||
ri_mutex.Unlock()
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func check_post(uri string) (PostJson, error) {
|
||||
// conn, _:= pool.Acquire(context.Background())
|
||||
// defer conn.Release()
|
||||
@ -105,11 +122,12 @@ func check_post(uri string) (PostJson, error) {
|
||||
postjson.instance = uri[8:endslash+8]
|
||||
|
||||
|
||||
client := http.Client{}
|
||||
o := GetHTTPSession(postjson.instance)
|
||||
// client := o.client
|
||||
req, _ := http.NewRequest("GET", uri, nil)
|
||||
req.Header.Add("Accept", "application/ld+json")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
resp, err := o.client.Do(req)
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(&postjson)
|
||||
if err != nil {
|
||||
@ -172,11 +190,12 @@ func check_user(uri string) (UserJson, error) {
|
||||
endslash := strings.Index(uri[8:], "/")
|
||||
userjson.instance = uri[8:endslash+8]
|
||||
|
||||
client := http.Client{}
|
||||
o := GetHTTPSession(userjson.instance)
|
||||
//client := http.Client{}
|
||||
req, _ := http.NewRequest("GET", uri, nil)
|
||||
req.Header.Add("Accept", "application/ld+json")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
resp, err := o.client.Do(req)
|
||||
if err != nil {
|
||||
//log.Fatal(err)
|
||||
return userjson, err
|
||||
|
Loading…
x
Reference in New Issue
Block a user