Skip to content

Commit 02c3626

Browse files
authored
Merge pull request #207 from tonkeeper/with-tonapi-key
Add WithTonApiKey function to client package
2 parents ce3697e + 2a37510 commit 02c3626

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

client/client_options.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package client
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
7+
ht "github.com/ogen-go/ogen/http"
8+
)
9+
10+
type clientWithApiKey struct {
11+
header string
12+
}
13+
14+
func (c clientWithApiKey) Do(r *http.Request) (*http.Response, error) {
15+
r.Header.Set("Authorization", c.header)
16+
return http.DefaultClient.Do(r)
17+
}
18+
19+
var _ ht.Client = &clientWithApiKey{}
20+
21+
// WithTonApiKey configures client to use tonApiKey for authorization.
22+
// When working with tonapi.io, you should consider getting an API key at https://tonconsole.com/.
23+
//
24+
// Example:
25+
//
26+
// import (
27+
//
28+
// tonapiClient "github.com/tonkeeper/opentonapi/client"
29+
//
30+
// )
31+
//
32+
// func main() {
33+
// cli, _ := tonapiClient.NewClient("https://tonapi.io", tonapiClient.WithTonApiKey(tonapiKey))
34+
// }
35+
func WithTonApiKey(tonApiKey string) ClientOption {
36+
return WithClient(&clientWithApiKey{header: fmt.Sprintf("Bearer %s", tonApiKey)})
37+
}

0 commit comments

Comments
 (0)