Browse Source

refactor(http): set user agent on instance of api.Client instead of package-level global

ayn2op 4 months ago
parent
commit
9d82a04727
2 changed files with 3 additions and 4 deletions
  1. 0 3
      cmd/state.go
  2. 3 1
      internal/http/client.go

+ 0 - 3
cmd/state.go

@@ -7,7 +7,6 @@ import (
 	"github.com/ayn2op/discordo/internal/http"
 	"github.com/ayn2op/discordo/internal/notifications"
 	"github.com/ayn2op/tview"
-	"github.com/diamondburned/arikawa/v3/api"
 	"github.com/diamondburned/arikawa/v3/gateway"
 	"github.com/diamondburned/arikawa/v3/session"
 	"github.com/diamondburned/arikawa/v3/state"
@@ -22,8 +21,6 @@ import (
 
 func openState(token string) error {
 	identifyProps := http.IdentifyProperties()
-
-	api.UserAgent = http.BrowserUserAgent
 	gateway.DefaultIdentity = identifyProps
 	gateway.DefaultPresence = &gateway.UpdatePresenceCommand{
 		Status: app.cfg.Status,

+ 3 - 1
internal/http/client.go

@@ -12,5 +12,7 @@ func NewClient(token string) *api.Client {
 	stdClient := http.DefaultClient
 	stdClient.Transport = NewTransport()
 	httpClient := httputil.NewClientWithDriver(httpdriver.WrapClient(*stdClient))
-	return api.NewCustomClient(token, httpClient)
+	apiClient := api.NewCustomClient(token, httpClient)
+	apiClient.UserAgent = BrowserUserAgent
+	return apiClient
 }