Skip to content

Commit bde4550

Browse files
committed
export the context field of the client
1 parent 78f5262 commit bde4550

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
// Using a client directly allows more fine-grained control over how downloading
2020
// is done, as well as customizing the protocols supported.
2121
type Client struct {
22-
// ctx for cancellation
23-
ctx context.Context
22+
// Ctx for cancellation
23+
Ctx context.Context
2424

2525
// Src is the source URL to get.
2626
//
@@ -291,7 +291,7 @@ func (c *Client) Get() error {
291291
return err
292292
}
293293

294-
return copyDir(c.ctx, realDst, subDir, false)
294+
return copyDir(c.Ctx, realDst, subDir, false)
295295
}
296296

297297
return nil

client_option.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ type ClientOption func(*Client) error
77

88
// Configure configures a client with options.
99
func (c *Client) Configure(opts ...ClientOption) error {
10-
c.ctx = context.Background()
10+
if c.Ctx == nil {
11+
c.Ctx = context.Background()
12+
}
1113
c.Options = opts
1214
for _, opt := range opts {
1315
err := opt(c)
@@ -38,7 +40,7 @@ func (c *Client) Configure(opts ...ClientOption) error {
3840
// in order to be able to cancel a download in progress.
3941
func WithContext(ctx context.Context) func(*Client) error {
4042
return func(c *Client) error {
41-
c.ctx = ctx
43+
c.Ctx = ctx
4244
return nil
4345
}
4446
}

cmd/go-getter/main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"os/signal"
99
"sync"
1010

11-
"github.com/hashicorp/go-getter"
11+
getter "github.com/hashicorp/go-getter"
1212
)
1313

1414
func main() {
@@ -41,16 +41,15 @@ func main() {
4141
log.Fatalf("Error getting wd: %s", err)
4242
}
4343

44-
ctx, cancel := context.WithCancel(context.Background())
45-
opts := []getter.ClientOption{
46-
getter.WithContext(ctx),
47-
}
44+
opts := []getter.ClientOption{}
4845
if *progress {
4946
opts = append(opts, getter.WithProgress(defaultProgressBar))
5047
}
5148

49+
ctx, cancel := context.WithCancel(context.Background())
5250
// Build the client
5351
client := &getter.Client{
52+
Ctx: ctx,
5453
Src: args[0],
5554
Dst: args[1],
5655
Pwd: pwd,

get_base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ func (g *getter) Context() context.Context {
1616
if g == nil || g.client == nil {
1717
return context.Background()
1818
}
19-
return g.client.ctx
19+
return g.client.Ctx
2020
}

0 commit comments

Comments
 (0)