Skip to content
Merged
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
7 changes: 5 additions & 2 deletions rest/rest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ func NewClient(botToken string, opts ...ConfigOpt) Client {

config.RateLimiter.Reset()

return &clientImpl{botToken: botToken, config: *config}
return &clientImpl{
botToken: botToken,
config: *config,
}
}

// Client allows doing requests to different endpoints
Expand Down Expand Up @@ -83,7 +86,7 @@ func (c *clientImpl) retry(endpoint *CompiledEndpoint, rqBody any, rsBody any, t
c.config.Logger.Tracef("request to %s, body: %s", endpoint.URL, string(rawRqBody))
}

rq, err := http.NewRequest(endpoint.Endpoint.Method, endpoint.URL, bytes.NewReader(rawRqBody))
rq, err := http.NewRequest(endpoint.Endpoint.Method, c.config.URL+endpoint.URL, bytes.NewReader(rawRqBody))
if err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions rest/rest_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rest

import (
"fmt"
"net/http"
"time"

Expand All @@ -12,6 +13,7 @@ func DefaultConfig() *Config {
return &Config{
Logger: log.Default(),
HTTPClient: &http.Client{Timeout: 20 * time.Second},
URL: fmt.Sprintf("%s/v%d", API, Version),
}
}

Expand All @@ -21,6 +23,7 @@ type Config struct {
HTTPClient *http.Client
RateLimiter RateLimiter
RateRateLimiterConfigOpts []RateLimiterConfigOpt
URL string
UserAgent string
}

Expand Down Expand Up @@ -65,6 +68,13 @@ func WithRateRateLimiterConfigOpts(opts ...RateLimiterConfigOpt) ConfigOpt {
}
}

// WithURL sets the api url for all requests
func WithURL(url string) ConfigOpt {
return func(config *Config) {
config.URL = url
}
}

// WithUserAgent sets the user agent for all requests
func WithUserAgent(userAgent string) ConfigOpt {
return func(config *Config) {
Expand Down
8 changes: 4 additions & 4 deletions rest/rest_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
)

var (
// APIVersion is the Discord API version DisGo should use
APIVersion = 10
// Version is the Discord API version DisGo should use
Version = 10

// API is the base path of the Discord API
API = fmt.Sprintf("https://discord.com/api/v%d", APIVersion)
API = "https://discord.com/api/"
)

// MajorParameters is a list of url parameters which decide in which bucket a route belongs (https://discord.com/developers/docs/topics/rate-limits#rate-limits)
Expand Down Expand Up @@ -346,7 +346,7 @@ func (e *Endpoint) Compile(values discord.QueryValues, params ...any) *CompiledE

return &CompiledEndpoint{
Endpoint: e,
URL: API + path + query,
URL: path + query,
MajorParams: strings.Join(majorParams, ":"),
}
}