Skip to content

Commit 90ea5c1

Browse files
committed
cmd/go-cache-plugin: use s3util.Client where appropriate
1 parent 7293cbc commit 90ea5c1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

cmd/go-cache-plugin/commands.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/creachadair/gocache/cachedir"
2525
"github.com/creachadair/taskgroup"
2626
"github.com/goproxy/goproxy"
27+
"github.com/tailscale/go-cache-plugin/internal/s3util"
2728
"github.com/tailscale/go-cache-plugin/s3cache"
2829
"github.com/tailscale/go-cache-plugin/s3proxy"
2930
"tailscale.com/tsweb"
@@ -43,7 +44,7 @@ var flags struct {
4344
DebugLog bool `flag:"debug,default=$GOCACHE_DEBUG,Enable detailed per-request debug logging (noisy)"`
4445
}
4546

46-
func initCacheServer(env *command.Env) (*gocache.Server, *s3.Client, error) {
47+
func initCacheServer(env *command.Env) (*gocache.Server, *s3util.Client, error) {
4748
switch {
4849
case flags.CacheDir == "":
4950
return nil, nil, env.Usagef("you must provide a --cache-dir")
@@ -67,10 +68,13 @@ func initCacheServer(env *command.Env) (*gocache.Server, *s3.Client, error) {
6768

6869
vprintf("local cache directory: %s", flags.CacheDir)
6970
vprintf("S3 cache bucket %q (%s)", flags.S3Bucket, region)
71+
client := &s3util.Client{
72+
Client: s3.NewFromConfig(cfg),
73+
Bucket: flags.S3Bucket,
74+
}
7075
cache := &s3cache.Cache{
7176
Local: dir,
72-
S3Client: s3.NewFromConfig(cfg),
73-
S3Bucket: flags.S3Bucket,
77+
S3Client: client,
7478
KeyPrefix: flags.KeyPrefix,
7579
MinUploadSize: flags.MinUploadSize,
7680
UploadConcurrency: flags.S3Concurrency,
@@ -94,7 +98,7 @@ func initCacheServer(env *command.Env) (*gocache.Server, *s3.Client, error) {
9498
LogRequests: flags.DebugLog,
9599
}
96100
expvar.Publish("gocache_server", s.Metrics().Get("server"))
97-
return s, cache.S3Client, nil
101+
return s, client, nil
98102
}
99103

100104
// runDirect runs a cache communicating on stdin/stdout, for use as a direct
@@ -162,7 +166,6 @@ func runServe(env *command.Env) error {
162166
cacher := &s3proxy.Cacher{
163167
Local: modCachePath,
164168
S3Client: s3c,
165-
S3Bucket: flags.S3Bucket,
166169
KeyPrefix: path.Join(flags.KeyPrefix, "module"),
167170
MaxTasks: flags.S3Concurrency,
168171
LogRequests: flags.DebugLog,

0 commit comments

Comments
 (0)