File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments