-
Notifications
You must be signed in to change notification settings - Fork 646
/
requester.go
48 lines (41 loc) · 907 Bytes
/
requester.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
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package rpc
import (
"context"
"fmt"
"net/url"
)
var _ EndpointRequester = &avalancheEndpointRequester{}
type EndpointRequester interface {
SendRequest(ctx context.Context, method string, params interface{}, reply interface{}, options ...Option) error
}
type avalancheEndpointRequester struct {
uri, base string
}
func NewEndpointRequester(uri, base string) EndpointRequester {
return &avalancheEndpointRequester{
uri: uri,
base: base,
}
}
func (e *avalancheEndpointRequester) SendRequest(
ctx context.Context,
method string,
params interface{},
reply interface{},
options ...Option,
) error {
uri, err := url.Parse(e.uri)
if err != nil {
return err
}
return SendJSONRequest(
ctx,
uri,
fmt.Sprintf("%s.%s", e.base, method),
params,
reply,
options...,
)
}