diff --git a/discord.go b/discord.go index 28f2460..eff8de9 100644 --- a/discord.go +++ b/discord.go @@ -13,7 +13,11 @@ // Package discordgo provides Discord binding for Go package discordgo -import "fmt" +import ( + "fmt" + "net/http" + "time" +) // VERSION of Discordgo, follows Symantic Versioning. (http://semver.org/) const VERSION = "0.16.0-dev" @@ -43,6 +47,7 @@ func New(args ...interface{}) (s *Session, err error) { ShardID: 0, ShardCount: 1, MaxRestRetries: 3, + Client: &http.Client{Timeout: (20 * time.Second)}, } // If no arguments are passed return the empty Session interface. diff --git a/restapi.go b/restapi.go index fd17d6b..ea0650d 100644 --- a/restapi.go +++ b/restapi.go @@ -87,9 +87,7 @@ func (s *Session) request(method, urlStr, contentType string, b []byte, bucketID } } - client := &http.Client{Timeout: (20 * time.Second)} - - resp, err := client.Do(req) + resp, err := s.Client.Do(req) if err != nil { bucket.Release(nil) return diff --git a/structs.go b/structs.go index 157b6b7..d2f5c2d 100644 --- a/structs.go +++ b/structs.go @@ -13,6 +13,7 @@ package discordgo import ( "encoding/json" + "net/http" "strconv" "sync" "time" @@ -73,6 +74,9 @@ type Session struct { // StateEnabled is true. State *State + // The http client used for REST requests + Client *http.Client + // Event handlers handlersMu sync.RWMutex handlers map[string][]*eventHandlerInstance