Reuse http client, and export it (#301)
This commit is contained in:
parent
b377944b97
commit
edc3213ffb
3 changed files with 11 additions and 4 deletions
|
@ -13,7 +13,11 @@
|
||||||
// Package discordgo provides Discord binding for Go
|
// Package discordgo provides Discord binding for Go
|
||||||
package discordgo
|
package discordgo
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// VERSION of Discordgo, follows Symantic Versioning. (http://semver.org/)
|
// VERSION of Discordgo, follows Symantic Versioning. (http://semver.org/)
|
||||||
const VERSION = "0.16.0-dev"
|
const VERSION = "0.16.0-dev"
|
||||||
|
@ -43,6 +47,7 @@ func New(args ...interface{}) (s *Session, err error) {
|
||||||
ShardID: 0,
|
ShardID: 0,
|
||||||
ShardCount: 1,
|
ShardCount: 1,
|
||||||
MaxRestRetries: 3,
|
MaxRestRetries: 3,
|
||||||
|
Client: &http.Client{Timeout: (20 * time.Second)},
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no arguments are passed return the empty Session interface.
|
// If no arguments are passed return the empty Session interface.
|
||||||
|
|
|
@ -87,9 +87,7 @@ func (s *Session) request(method, urlStr, contentType string, b []byte, bucketID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client := &http.Client{Timeout: (20 * time.Second)}
|
resp, err := s.Client.Do(req)
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bucket.Release(nil)
|
bucket.Release(nil)
|
||||||
return
|
return
|
||||||
|
|
|
@ -13,6 +13,7 @@ package discordgo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -73,6 +74,9 @@ type Session struct {
|
||||||
// StateEnabled is true.
|
// StateEnabled is true.
|
||||||
State *State
|
State *State
|
||||||
|
|
||||||
|
// The http client used for REST requests
|
||||||
|
Client *http.Client
|
||||||
|
|
||||||
// Event handlers
|
// Event handlers
|
||||||
handlersMu sync.RWMutex
|
handlersMu sync.RWMutex
|
||||||
handlers map[string][]*eventHandlerInstance
|
handlers map[string][]*eventHandlerInstance
|
||||||
|
|
Loading…
Reference in a new issue