Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions examples/v2/timeout/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"context"
"fmt"
"log"
"net/http"
"os"
"time"

"github.com/FuzzyStatic/blizzard/v2"
)

var (
clientID string
clientSecret string
blizz *blizzard.Client
)

func init() {
clientID = os.Getenv("CLIENT_ID")
if clientID == "" {
log.Fatal("Set the environment variable CLIENT_ID before retrying.")
}

clientSecret = os.Getenv("CLIENT_SECRET")
if clientSecret == "" {
log.Fatal("Set the environment variable CLIENT_SECRET before retrying.")
}
}

func main() {
blizz = blizzard.NewClient(
clientID,
clientSecret,
blizzard.US,
blizzard.EnUS,
)

blizz.SetHTTPClient(clientWithTimeout(blizz.GetHTTPClient()))

err := blizz.AccessTokenRequest(context.Background())
if err != nil {
fmt.Println(err)
}
}

func clientWithTimeout(c *http.Client) *http.Client {
c.Timeout = 10 * time.Second
return c
}
13 changes: 13 additions & 0 deletions v2/blizzard.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ func (c *Client) GetStaticClassicNamespace() string {
return c.staticClassicNamespace
}

// GetHTTPClient returns the http.Client used for making requests
func (c *Client) GetHTTPClient() *http.Client {
return c.httpClient
}

// SetHTTPClient sets the http.Client used for making requests.
// Calling `SetRegion` will overwrite this client.
// It is recommended to wrap the client returned by `GetHTTPClient` because
// the default one handles the oauth flow (see `golang.org/x/oauth2.NewClient`).
func (c *Client) SetHTTPClient(h *http.Client) {
c.httpClient = h
}

// buildSearchParams builds params for searches
func buildSearchParams(opts ...wowsearch.Opt) string {
if len(opts) == 0 {
Expand Down