forked from infobloxopen/atlas-app-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
29 lines (26 loc) · 717 Bytes
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package integration
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"github.com/prateeksuresh23/atlas-app-toolkit/auth"
)
// MakeStandardRequest issues an HTTP request a specific endpoint with Atlas-specific
// request data (e.g. the authorization token)
func MakeStandardRequest(method, url string, payload interface{}) (*http.Request, error) {
body, err := json.Marshal(payload)
if err != nil {
return nil, err
}
req, err := http.NewRequest(method, url, bytes.NewBuffer(body))
if err != nil {
return nil, err
}
token, err := StandardTestJWT()
if err != nil {
return nil, err
}
req.Header.Set(auth.AuthorizationHeader, fmt.Sprintf("%s %s", auth.DefaultTokenType, token))
return req, nil
}