MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / newRequest

Method newRequest

api/pkg/discord/client.go:57–79  ·  view source on GitHub ↗

newRequest creates an API request. A relative URL can be provided in uri, in which case it is resolved relative to the BaseURL of the Client. URI's should always be specified without a preceding slash.

(ctx context.Context, method, uri string, body any)

Source from the content-addressed store, hash-verified

55// in which case it is resolved relative to the BaseURL of the Client.
56// URI's should always be specified without a preceding slash.
57func (client *Client) newRequest(ctx context.Context, method, uri string, body any) (*http.Request, error) {
58 var buf io.ReadWriter
59 if body != nil {
60 buf = &bytes.Buffer{}
61 enc := json.NewEncoder(buf)
62 enc.SetEscapeHTML(false)
63 err := enc.Encode(body)
64 if err != nil {
65 return nil, err
66 }
67 }
68
69 req, err := http.NewRequestWithContext(ctx, method, client.baseURL+uri, buf)
70 if err != nil {
71 return nil, err
72 }
73
74 req.Header.Set("Content-Type", "application/json")
75 req.Header.Set("Accept", "application/json")
76 req.Header.Set("Authorization", "Bot "+client.botToken)
77
78 return req, nil
79}
80
81// do carries out an HTTP request and returns a Response
82func (client *Client) do(req *http.Request) (*Response, error) {

Callers 4

CreateCommandMethod · 0.80
CreateMessageMethod · 0.80
GetMethod · 0.80
GetMethod · 0.80

Calls 1

SetMethod · 0.65

Tested by

no test coverage detected