mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-01-22 04:26:47 +00:00
api: Add *Client.WithLocale
This commit is contained in:
parent
55f0b1eda9
commit
7ed7983b7b
17
api/api.go
17
api/api.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/diamondburned/arikawa/v3/api/rate"
|
"github.com/diamondburned/arikawa/v3/api/rate"
|
||||||
|
"github.com/diamondburned/arikawa/v3/discord"
|
||||||
"github.com/diamondburned/arikawa/v3/utils/httputil"
|
"github.com/diamondburned/arikawa/v3/utils/httputil"
|
||||||
"github.com/diamondburned/arikawa/v3/utils/httputil/httpdriver"
|
"github.com/diamondburned/arikawa/v3/utils/httputil/httpdriver"
|
||||||
)
|
)
|
||||||
|
@ -49,6 +50,22 @@ func NewCustomClient(token string, httpClient *httputil.Client) *Client {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithLocale creates a copy of Client with an explicitly stated language locale
|
||||||
|
// using the X-Discord-Locale HTTP header.
|
||||||
|
func (c *Client) WithLocale(language discord.Language) *Client {
|
||||||
|
client := c.Client.Copy()
|
||||||
|
client.OnRequest = append(client.OnRequest, func(r httpdriver.Request) error {
|
||||||
|
r.AddHeader(http.Header{"X-Discord-Locale": []string{string(language)}})
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return &Client{
|
||||||
|
Client: client,
|
||||||
|
Session: c.Session,
|
||||||
|
AcquireOptions: c.AcquireOptions,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithContext returns a shallow copy of Client with the given context. It's
|
// WithContext returns a shallow copy of Client with the given context. It's
|
||||||
// used for method timeouts and such. This method is thread-safe.
|
// used for method timeouts and such. This method is thread-safe.
|
||||||
func (c *Client) WithContext(ctx context.Context) *Client {
|
func (c *Client) WithContext(ctx context.Context) *Client {
|
||||||
|
|
Loading…
Reference in a new issue