forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
51 lines (41 loc) · 842 Bytes
/
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
51
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package rpc
import (
"net/http"
"net/url"
)
type Option func(*Options)
type Options struct {
headers http.Header
queryParams url.Values
}
func NewOptions(ops []Option) *Options {
o := &Options{
headers: http.Header{},
queryParams: url.Values{},
}
o.applyOptions(ops)
return o
}
func (o *Options) applyOptions(ops []Option) {
for _, op := range ops {
op(o)
}
}
func (o *Options) Headers() http.Header {
return o.headers
}
func (o *Options) QueryParams() url.Values {
return o.queryParams
}
func WithHeader(key, val string) Option {
return func(o *Options) {
o.headers.Set(key, val)
}
}
func WithQueryParam(key, val string) Option {
return func(o *Options) {
o.queryParams.Set(key, val)
}
}