Skip to content

Commit 3455691

Browse files
author
eugeneslavyansky
committed
New
1 parent 4e1eaff commit 3455691

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ View [API Documentation](https://www.bitgo.com/api/v2).
2222

2323
## List Wallets
2424
```go
25-
b, err := bitgo.New("test", "{Access token}", time.Minute)
25+
b, err := bitgo.New("test", time.Minute)
2626
if err != nil {
2727
log.Fatal(err.Error())
2828
}
2929

30-
list, err := b.Coin("tbtc").Debug(true).ListWallets(bitgo.ListParams{
30+
list, err := b.Token("{Access token}").Coin("tbtc").Debug(true).ListWallets(bitgo.ListParams{
3131
AllTokens: true,
3232
})
3333
if err != nil {
34-
log.Fatal(err.Error())
34+
log.Fatalf("%#v\n", err.(bitgo.Error))
3535
}
3636

3737
for _, w := range list.Wallets {

examples/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import (
88
)
99

1010
func main() {
11-
b, err := bitgo.New("test", "{Access token}", time.Minute)
11+
b, err := bitgo.New("test", time.Minute)
1212
if err != nil {
1313
log.Fatal(err.Error())
1414
}
1515

16-
list, err := b.Coin("tbtc").Debug(true).ListWallets(bitgo.ListParams{
16+
list, err := b.Token("{Access token}").Coin("tbtc").Debug(true).ListWallets(bitgo.ListParams{
1717
AllTokens: true,
1818
})
1919
if err != nil {
20-
log.Fatal(err.Error())
20+
log.Fatalf("%#v\n", err.(bitgo.Error))
2121
}
2222

2323
for _, w := range list.Wallets {

main.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type ListParams struct {
2727
AllTokens bool `url:"allTokens,omitempty"`
2828
}
2929

30-
func New(env string, token string, timeout time.Duration) (b *BitGo, err error) {
30+
func New(env string, timeout time.Duration) (b *BitGo, err error) {
3131
if env == "" {
3232
return nil, errors.New("empty env")
3333
}
@@ -39,7 +39,6 @@ func New(env string, token string, timeout time.Duration) (b *BitGo, err error)
3939
}
4040
return &BitGo{
4141
host: env + "/api/v2",
42-
token: token,
4342
timeout: timeout,
4443
}, nil
4544
}
@@ -54,6 +53,12 @@ func (b *BitGo) clone() *BitGo {
5453
}
5554
}
5655

56+
func (b *BitGo) Token(token string) *BitGo {
57+
c := b.clone()
58+
c.token = token
59+
return c
60+
}
61+
5762
func (b *BitGo) Coin(coin string) *BitGo {
5863
c := b.clone()
5964
c.coin = coin

test_utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ func getTestParams() (params *TestParams) {
4646
func getTestBitGo(t *testing.T) (b *BitGo, params *TestParams) {
4747
params = getTestParams()
4848

49-
b, err := New(params.Env, params.Token, time.Minute*5)
49+
b, err := New(params.Env, time.Minute*5)
5050
if err != nil {
5151
t.Fatal(err)
5252
}
5353

54-
return b.Debug(false), params
54+
return b.Token(params.Token).Debug(false), params
5555
}
5656

5757
func getTestCoin(t *testing.T) (coin *BitGo, params *TestParams) {

0 commit comments

Comments
 (0)