MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / newHTTPRequest

Function newHTTPRequest

pkg/interop/client.go:77–96  ·  view source on GitHub ↗
(
	url string, pld any, headers map[string]string, username, password string,
)

Source from the content-addressed store, hash-verified

75}
76
77func newHTTPRequest(
78 url string, pld any, headers map[string]string, username, password string,
79) (*http.Request, error) {
80 buf := &bytes.Buffer{}
81 if err := json.NewEncoder(buf).Encode(pld); err != nil {
82 return nil, err
83 }
84 req, err := http.NewRequest(http.MethodPost, url, buf)
85 if err != nil {
86 return nil, err
87 }
88 req.Header.Set("Content-Type", "application/json")
89 for k, v := range headers {
90 req.Header.Set(k, v)
91 }
92 if username != "" {
93 req.SetBasicAuth(username, password)
94 }
95 return req, nil
96}
97
98func httpExchange(
99 ctx context.Context, httpReq *http.Request, res any, do func(*http.Request) (*http.Response, error),

Callers 1

exchangeMethod · 0.85

Calls 3

NewEncoderMethod · 0.80
EncodeMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected