diff --git a/api/channel.go b/api/channel.go index 4d8f463..5af7f49 100644 --- a/api/channel.go +++ b/api/channel.go @@ -42,7 +42,7 @@ func (c *Client) CreateChannel( return ch, c.RequestJSON( &ch, "POST", EndpointGuilds+guildID.String()+"/channels", - httputil.WithJSONBody(c, data), + httputil.WithJSONBody(data), ) } @@ -57,7 +57,7 @@ func (c *Client) MoveChannel(guildID discord.Snowflake, datum []MoveChannelData) return c.FastRequest( "PATCH", EndpointGuilds+guildID.String()+"/channels", - httputil.WithJSONBody(c, datum), + httputil.WithJSONBody(datum), ) } @@ -93,7 +93,7 @@ func (c *Client) ModifyChannel(channelID discord.Snowflake, data ModifyChannelDa return c.FastRequest( "PATCH", EndpointChannels+channelID.String(), - httputil.WithJSONBody(c, data), + httputil.WithJSONBody(data), ) } @@ -107,7 +107,7 @@ func (c *Client) EditChannelPermission( url := EndpointChannels + channelID.String() + "/permissions/" + overwrite.ID.String() overwrite.ID = 0 - return c.FastRequest("PUT", url, httputil.WithJSONBody(c, overwrite)) + return c.FastRequest("PUT", url, httputil.WithJSONBody(overwrite)) } func (c *Client) DeleteChannelPermission(channelID, overwriteID discord.Snowflake) error { @@ -153,7 +153,7 @@ func (c *Client) AddRecipient( return c.FastRequest( "PUT", EndpointChannels+channelID.String()+"/recipients/"+userID.String(), - httputil.WithJSONBody(c, params), + httputil.WithJSONBody(params), ) } @@ -176,6 +176,6 @@ func (c *Client) Ack(channelID, messageID discord.Snowflake, ack *Ack) error { ack, "POST", EndpointChannels+channelID.String()+ "/messages/"+messageID.String()+"/ack", - httputil.WithJSONBody(c, ack), + httputil.WithJSONBody(ack), ) } diff --git a/api/emoji.go b/api/emoji.go index 4564f12..e99e6f4 100644 --- a/api/emoji.go +++ b/api/emoji.go @@ -59,7 +59,7 @@ func (c *Client) CreateEmoji( return emj, c.RequestJSON( &emj, "POST", EndpointGuilds+guildID.String()+"/emojis", - httputil.WithJSONBody(c, param), + httputil.WithJSONBody(param), ) } @@ -80,7 +80,7 @@ func (c *Client) ModifyEmoji( return c.FastRequest( "PATCH", EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String(), - httputil.WithJSONBody(c, param), + httputil.WithJSONBody(param), ) } diff --git a/api/guild.go b/api/guild.go index 98dc26e..42a1c7c 100644 --- a/api/guild.go +++ b/api/guild.go @@ -32,7 +32,7 @@ type CreateGuildData struct { func (c *Client) CreateGuild(data CreateGuildData) (*discord.Guild, error) { var g *discord.Guild - return g, c.RequestJSON(&g, "POST", Endpoint+"guilds", httputil.WithJSONBody(c, data)) + return g, c.RequestJSON(&g, "POST", Endpoint+"guilds", httputil.WithJSONBody(data)) } func (c *Client) Guild(id discord.Snowflake) (*discord.Guild, error) { @@ -148,7 +148,7 @@ func (c *Client) ModifyGuild(id discord.Snowflake, data ModifyGuildData) (*disco return g, c.RequestJSON( &g, "PATCH", EndpointGuilds+id.String(), - httputil.WithJSONBody(c, data), + httputil.WithJSONBody(data), ) } @@ -214,7 +214,7 @@ func (c *Client) AttachIntegration( return c.FastRequest( "POST", EndpointGuilds+guildID.String()+"/integrations", - httputil.WithJSONBody(c, param), + httputil.WithJSONBody(param), ) } diff --git a/api/login.go b/api/login.go index 5913b7e..1fdd0f6 100644 --- a/api/login.go +++ b/api/login.go @@ -24,8 +24,7 @@ func (c *Client) Login(email, password string) (*LoginResponse, error) { param.Password = password var r *LoginResponse - return r, c.RequestJSON(&r, "POST", EndpointLogin, - httputil.WithJSONBody(c, param)) + return r, c.RequestJSON(&r, "POST", EndpointLogin, httputil.WithJSONBody(param)) } func (c *Client) TOTP(code, ticket string) (*LoginResponse, error) { @@ -37,6 +36,5 @@ func (c *Client) TOTP(code, ticket string) (*LoginResponse, error) { param.Ticket = ticket var r *LoginResponse - return r, c.RequestJSON(&r, "POST", EndpointTOTP, - httputil.WithJSONBody(c, param)) + return r, c.RequestJSON(&r, "POST", EndpointTOTP, httputil.WithJSONBody(param)) } diff --git a/api/member.go b/api/member.go index 42be17e..79aea47 100644 --- a/api/member.go +++ b/api/member.go @@ -113,7 +113,7 @@ func (c *Client) AddMember( return mem, c.RequestJSON( &mem, "PUT", EndpointGuilds+guildID.String()+"/members/"+userID.String(), - httputil.WithJSONBody(c, param), + httputil.WithJSONBody(param), ) } @@ -123,7 +123,7 @@ func (c *Client) ModifyMember( return c.FastRequest( "PATCH", EndpointGuilds+guildID.String()+"/members/"+userID.String(), - httputil.WithJSONBody(c, data), + httputil.WithJSONBody(data), ) } diff --git a/api/message.go b/api/message.go index fa4872e..fab0124 100644 --- a/api/message.go +++ b/api/message.go @@ -130,7 +130,7 @@ func (c *Client) EditMessage( return msg, c.RequestJSON( &msg, "PATCH", EndpointChannels+channelID.String()+"/messages/"+messageID.String(), - httputil.WithJSONBody(c, param), + httputil.WithJSONBody(param), ) } @@ -151,5 +151,5 @@ func (c *Client) DeleteMessages(channelID discord.Snowflake, messageIDs []discor param.Messages = messageIDs return c.FastRequest("POST", EndpointChannels+channelID.String()+ - "/messages/bulk-delete", httputil.WithJSONBody(c, param)) + "/messages/bulk-delete", httputil.WithJSONBody(param)) } diff --git a/api/role.go b/api/role.go index 54dcaea..8d5a068 100644 --- a/api/role.go +++ b/api/role.go @@ -39,7 +39,7 @@ func (c *Client) CreateRole( return role, c.RequestJSON( &role, "POST", EndpointGuilds+guildID.String()+"/roles", - httputil.WithJSONBody(c, data), + httputil.WithJSONBody(data), ) } @@ -58,7 +58,7 @@ func (c *Client) MoveRole( return roles, c.RequestJSON( &roles, "PATCH", EndpointGuilds+guildID.String()+"/roles", - httputil.WithJSONBody(c, param), + httputil.WithJSONBody(param), ) } @@ -70,7 +70,7 @@ func (c *Client) ModifyRole( return role, c.RequestJSON( &role, "PATCH", EndpointGuilds+guildID.String()+"/roles/"+roleID.String(), - httputil.WithJSONBody(c, data), + httputil.WithJSONBody(data), ) } diff --git a/api/send.go b/api/send.go index e1a22a8..b3cb74d 100644 --- a/api/send.go +++ b/api/send.go @@ -107,8 +107,8 @@ type SendMessageData struct { AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"` } -func (data *SendMessageData) WriteMultipart(c json.Driver, body *multipart.Writer) error { - return writeMultipart(c, body, data, data.Files) +func (data *SendMessageData) WriteMultipart(body *multipart.Writer) error { + return writeMultipart(body, data, data.Files) } func (c *Client) SendMessageComplex( @@ -135,11 +135,11 @@ func (c *Client) SendMessageComplex( if len(data.Files) == 0 { // No files, so no need for streaming. - return msg, c.RequestJSON(&msg, "POST", URL, httputil.WithJSONBody(c, data)) + return msg, c.RequestJSON(&msg, "POST", URL, httputil.WithJSONBody(data)) } writer := func(mw *multipart.Writer) error { - return data.WriteMultipart(c, mw) + return data.WriteMultipart(mw) } resp, err := c.MeanwhileMultipart(writer, "POST", URL) @@ -150,7 +150,7 @@ func (c *Client) SendMessageComplex( var body = resp.GetBody() defer body.Close() - return msg, c.DecodeStream(body, &msg) + return msg, json.DecodeStream(body, &msg) } type ExecuteWebhookData struct { @@ -170,8 +170,8 @@ type ExecuteWebhookData struct { AvatarURL discord.URL `json:"avatar_url,omitempty"` } -func (data *ExecuteWebhookData) WriteMultipart(c json.Driver, body *multipart.Writer) error { - return writeMultipart(c, body, data, data.Files) +func (data *ExecuteWebhookData) WriteMultipart(body *multipart.Writer) error { + return writeMultipart(body, data, data.Files) } // ExecuteWebhook sends a message to the webhook. If wait is bool, Discord will @@ -210,11 +210,11 @@ func (c *Client) ExecuteWebhook( if len(data.Files) == 0 { // No files, so no need for streaming. return msg, c.RequestJSON(&msg, "POST", URL, - httputil.WithJSONBody(c, data)) + httputil.WithJSONBody(data)) } writer := func(mw *multipart.Writer) error { - return data.WriteMultipart(c, mw) + return data.WriteMultipart(mw) } resp, err := c.MeanwhileMultipart(writer, "POST", URL) @@ -230,13 +230,10 @@ func (c *Client) ExecuteWebhook( return nil, nil } - return msg, c.DecodeStream(body, &msg) + return msg, json.DecodeStream(body, &msg) } -func writeMultipart( - c json.Driver, body *multipart.Writer, - item interface{}, files []SendMessageFile) error { - +func writeMultipart(body *multipart.Writer, item interface{}, files []SendMessageFile) error { defer body.Close() // Encode the JSON body first @@ -245,7 +242,7 @@ func writeMultipart( return errors.Wrap(err, "Failed to create bodypart for JSON") } - if err := c.EncodeStream(w, item); err != nil { + if err := json.EncodeStream(w, item); err != nil { return errors.Wrap(err, "Failed to encode JSON") } diff --git a/api/user.go b/api/user.go index d412f04..3fb4792 100644 --- a/api/user.go +++ b/api/user.go @@ -47,7 +47,7 @@ func (c *Client) CreatePrivateChannel( var dm *discord.Channel return dm, c.RequestJSON(&dm, "POST", EndpointMe+"/channels", - httputil.WithJSONBody(c, param)) + httputil.WithJSONBody(param)) } // ChangeOwnNickname only replies with the nickname back, so we're not even @@ -64,7 +64,7 @@ func (c *Client) ChangeOwnNickname( return c.FastRequest( "PATCH", EndpointGuilds+guildID.String()+"/members/@me/nick", - httputil.WithJSONBody(c, param), + httputil.WithJSONBody(param), ) } diff --git a/api/webhook.go b/api/webhook.go index 817e759..c44b25c 100644 --- a/api/webhook.go +++ b/api/webhook.go @@ -25,7 +25,7 @@ func (c *Client) CreateWebhook( return w, c.RequestJSON( &w, "POST", EndpointChannels+channelID.String()+"/webhooks", - httputil.WithJSONBody(c, param), + httputil.WithJSONBody(param), ) } diff --git a/utils/httputil/client.go b/utils/httputil/client.go index 8788df7..bd85ced 100644 --- a/utils/httputil/client.go +++ b/utils/httputil/client.go @@ -23,7 +23,6 @@ var Retries uint = 5 type Client struct { httpdriver.Client - json.Driver SchemaEncoder // OnRequest, if not nil, will be copied and prefixed on each Request. @@ -42,7 +41,6 @@ type Client struct { func NewClient() *Client { return &Client{ Client: httpdriver.NewClient(), - Driver: json.Default, SchemaEncoder: &DefaultSchema{}, Retries: Retries, context: context.Background(), @@ -147,7 +145,7 @@ func (c *Client) RequestJSON(to interface{}, method, url string, opts ...Request return nil } - if err := c.DecodeStream(body, to); err != nil { + if err := json.DecodeStream(body, to); err != nil { return JSONError{err} } @@ -211,7 +209,7 @@ func (c *Client) Request(method, url string, opts ...RequestOption) (httpdriver. } // Optionally unmarshal the error. - c.Unmarshal(httpErr.Body, &httpErr) + json.Unmarshal(httpErr.Body, &httpErr) return nil, httpErr } diff --git a/utils/httputil/options.go b/utils/httputil/options.go index 7858546..786e608 100644 --- a/utils/httputil/options.go +++ b/utils/httputil/options.go @@ -68,7 +68,7 @@ func WithBody(body io.ReadCloser) RequestOption { } // WithJSONBody inserts a JSON body into the request. This ignores JSON errors. -func WithJSONBody(json json.Driver, v interface{}) RequestOption { +func WithJSONBody(v interface{}) RequestOption { if v == nil { return func(httpdriver.Request) error { return nil