-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
50 lines (42 loc) · 1.24 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
44
45
46
47
48
49
50
package client
import "net/http"
// Var adds a variable into the outgoing request
func Var(name string, value interface{}) Option {
return func(bd *Request) {
if bd.Variables == nil {
bd.Variables = map[string]interface{}{}
}
bd.Variables[name] = value
}
}
// Operation sets the operation name for the outgoing request
func Operation(name string) Option {
return func(bd *Request) {
bd.OperationName = name
}
}
// Path 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 Path(url string) Option {
return func(bd *Request) {
bd.HTTP.URL.Path = url
}
}
// 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)
}
}