-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
43 lines (37 loc) · 1.11 KB
/
options.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package client
import (
"bytes"
"io/ioutil"
"net/http"
)
// Operation sets the operation name for the outgoing request
func Body(payload string) Option {
return func(bd *Request) {
bd.HTTP.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(payload)))
}
}
// Prefix sets the url that this request will be made against, useful if you are mounting your entire router
// and need to specify the url to the graphql endpoint.
func Prefix(urlPrefix string) Option {
return func(bd *Request) {
bd.HTTP.URL.Path = urlPrefix + bd.HTTP.URL.Path
}
}
// AddHeader adds a header to the outgoing request. This is useful for setting expected Authentication headers for example.
func AddHeader(key string, value string) Option {
return func(bd *Request) {
bd.HTTP.Header.Add(key, value)
}
}
// BasicAuth authenticates the request using http basic auth.
func BasicAuth(username, password string) Option {
return func(bd *Request) {
bd.HTTP.SetBasicAuth(username, password)
}
}
// AddCookie adds a cookie to the outgoing request
func AddCookie(cookie *http.Cookie) Option {
return func(bd *Request) {
bd.HTTP.AddCookie(cookie)
}
}