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) {
|
func check_post(uri string) (PostJson, error) {
|
||||||
// conn, _:= pool.Acquire(context.Background())
|
// conn, _:= pool.Acquire(context.Background())
|
||||||
// defer conn.Release()
|
// defer conn.Release()
|
||||||
@ -105,11 +122,12 @@ func check_post(uri string) (PostJson, error) {
|
|||||||
postjson.instance = uri[8:endslash+8]
|
postjson.instance = uri[8:endslash+8]
|
||||||
|
|
||||||
|
|
||||||
client := http.Client{}
|
o := GetHTTPSession(postjson.instance)
|
||||||
|
// client := o.client
|
||||||
req, _ := http.NewRequest("GET", uri, nil)
|
req, _ := http.NewRequest("GET", uri, nil)
|
||||||
req.Header.Add("Accept", "application/ld+json")
|
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)
|
err = json.NewDecoder(resp.Body).Decode(&postjson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -172,11 +190,12 @@ func check_user(uri string) (UserJson, error) {
|
|||||||
endslash := strings.Index(uri[8:], "/")
|
endslash := strings.Index(uri[8:], "/")
|
||||||
userjson.instance = uri[8:endslash+8]
|
userjson.instance = uri[8:endslash+8]
|
||||||
|
|
||||||
client := http.Client{}
|
o := GetHTTPSession(userjson.instance)
|
||||||
|
//client := http.Client{}
|
||||||
req, _ := http.NewRequest("GET", uri, nil)
|
req, _ := http.NewRequest("GET", uri, nil)
|
||||||
req.Header.Add("Accept", "application/ld+json")
|
req.Header.Add("Accept", "application/ld+json")
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := o.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//log.Fatal(err)
|
//log.Fatal(err)
|
||||||
return userjson, err
|
return userjson, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user