-
Notifications
You must be signed in to change notification settings - Fork 24
/
client.go
50 lines (41 loc) · 1.09 KB
/
client.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 tonapi
import (
"fmt"
"net/http"
ht "github.com/ogen-go/ogen/http"
)
type clientWithApiKey struct {
header string
}
func (c clientWithApiKey) Do(r *http.Request) (*http.Response, error) {
r.Header.Set("Authorization", c.header)
return http.DefaultClient.Do(r)
}
var _ ht.Client = &clientWithApiKey{}
// WithToken configures client to use tonApiKey for authorization.
// When working with tonapi.io, you should consider getting an API key at https://tonconsole.com/.
//
// Example:
//
// import (
//
// "github.com/tonkeeper/tonapi-go"
//
// )
//
// func main() {
// cli, _ := tonapi.New(tonapi.WithToken(tonapiKey))
// }
func WithToken(tonApiKey string) ClientOption {
return WithClient(&clientWithApiKey{header: fmt.Sprintf("Bearer %s", tonApiKey)})
}
const TonApiURL = "https://tonapi.io"
// TestnetTonApiURL is an endpoint to work with testnet.
//
// Example:
// client, err := NewClient(tonapi.TestnetTonApiURL)
const TestnetTonApiURL = "https://testnet.tonapi.io"
// New returns a new Client.
func New(opts ...ClientOption) (*Client, error) {
return NewClient(TonApiURL, opts...)
}