Skip to content

Commit 1248f9d

Browse files
committed
modproxy: rename s3proxy.Cacher to modproxy.S3Cacher
1 parent b0cc90a commit 1248f9d

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

cmd/go-cache-plugin/setup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
"github.com/goproxy/goproxy"
3030
"github.com/tailscale/go-cache-plugin/gobuild"
3131
"github.com/tailscale/go-cache-plugin/lib/s3util"
32+
"github.com/tailscale/go-cache-plugin/modproxy"
3233
"github.com/tailscale/go-cache-plugin/revproxy"
33-
"github.com/tailscale/go-cache-plugin/s3proxy"
3434
"tailscale.com/tsweb"
3535
)
3636

@@ -105,7 +105,7 @@ func initModProxy(env *command.Env, s3c *s3util.Client) (_ http.Handler, cleanup
105105
if err := os.MkdirAll(modCachePath, 0700); err != nil {
106106
return nil, nil, fmt.Errorf("create module cache: %w", err)
107107
}
108-
cacher := &s3proxy.Cacher{
108+
cacher := &modproxy.S3Cacher{
109109
Local: modCachePath,
110110
S3Client: s3c,
111111
KeyPrefix: path.Join(flags.KeyPrefix, "module"),

s3proxy/s3proxy.go renamed to modproxy/modproxy.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Tailscale Inc & AUTHORS
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
// Package s3proxy implements components of a Go module proxy that caches files
5-
// locally on disk, backed by objects in an S3 bucket.
6-
package s3proxy
4+
// Package modproxy implements components of a Go module proxy that caches
5+
// files locally on disk, backed by objects in an S3 bucket.
6+
package modproxy
77

88
import (
99
"bytes"
@@ -28,10 +28,10 @@ import (
2828
"golang.org/x/sync/semaphore"
2929
)
3030

31-
var _ goproxy.Cacher = (*Cacher)(nil)
31+
var _ goproxy.Cacher = (*S3Cacher)(nil)
3232

33-
// Cacher implements the [github.com/goproxy/goproxy.Cacher] interface using a
34-
// local disk cache backed by an S3 bucket.
33+
// S3Cacher implements the [github.com/goproxy/goproxy.Cacher] interface using
34+
// a local disk cache backed by an S3 bucket.
3535
//
3636
// # Cache Layout
3737
//
@@ -48,7 +48,7 @@ var _ goproxy.Cacher = (*Cacher)(nil)
4848
// the specified key prefix instead:
4949
//
5050
// <key-prefix>/module/16/0db4d719252162c87a9169e26deda33d2340770d0d540fd4c580c55008b2d6
51-
type Cacher struct {
51+
type S3Cacher struct {
5252
// Local is the path of a local cache directory where modules are cached.
5353
// It must be non-empty.
5454
Local string
@@ -114,7 +114,7 @@ type Cacher struct {
114114
putS3Bytes expvar.Int // put: total bytes written to S3
115115
}
116116

117-
func (c *Cacher) init() {
117+
func (c *S3Cacher) init() {
118118
c.initOnce.Do(func() {
119119
nt := c.MaxTasks
120120
if nt <= 0 {
@@ -127,7 +127,7 @@ func (c *Cacher) init() {
127127

128128
// Get implements a method of the goproxy.Cacher interface. It reports cache
129129
// hits out of the local directory if available, or faults in from S3.
130-
func (c *Cacher) Get(ctx context.Context, name string) (_ io.ReadCloser, oerr error) {
130+
func (c *S3Cacher) Get(ctx context.Context, name string) (_ io.ReadCloser, oerr error) {
131131
c.init()
132132
c.getRequest.Add(1)
133133
start := time.Now()
@@ -179,7 +179,7 @@ func (c *Cacher) Get(ctx context.Context, name string) (_ io.ReadCloser, oerr er
179179

180180
// putLocal reports whether the specified path already exists in the local
181181
// cache, and if not, writes data atomically into the path.
182-
func (c *Cacher) putLocal(ctx context.Context, name, path string, data io.Reader) (bool, error) {
182+
func (c *S3Cacher) putLocal(ctx context.Context, name, path string, data io.Reader) (bool, error) {
183183
if _, err := os.Stat(path); err == nil {
184184
return true, nil
185185
}
@@ -193,7 +193,7 @@ func (c *Cacher) putLocal(ctx context.Context, name, path string, data io.Reader
193193

194194
// Put implements a method of the goproxy.Cacher interface. It stores data into
195195
// the local directory and then writes it back to S3 in the background.
196-
func (c *Cacher) Put(ctx context.Context, name string, data io.ReadSeeker) (oerr error) {
196+
func (c *S3Cacher) Put(ctx context.Context, name string, data io.ReadSeeker) (oerr error) {
197197
c.init()
198198
c.putRequest.Add(1)
199199
start := time.Now()
@@ -240,14 +240,14 @@ func (c *Cacher) Put(ctx context.Context, name string, data io.ReadSeeker) (oerr
240240
}
241241

242242
// Close waits until all background updates are complete.
243-
func (c *Cacher) Close() error {
243+
func (c *S3Cacher) Close() error {
244244
c.init()
245245
return c.tasks.Wait()
246246
}
247247

248248
// Metrics returns a map of cacher metrics. The caller is responsible for
249249
// publishing these metrics.
250-
func (c *Cacher) Metrics() *expvar.Map {
250+
func (c *S3Cacher) Metrics() *expvar.Map {
251251
m := new(expvar.Map)
252252
m.Set("path_error", &c.pathError)
253253
m.Set("get_request", &c.getRequest)
@@ -273,13 +273,13 @@ func hashName(name string) string {
273273

274274
// makeKey assembles a complete S3 key from the specified parts, including the
275275
// key prefix if one is defined.
276-
func (c *Cacher) makeKey(hash string) string {
276+
func (c *S3Cacher) makeKey(hash string) string {
277277
return path.Join(c.KeyPrefix, hash[:2], hash)
278278
}
279279

280280
// makePath assembles a complete local cache path for the given name, creating
281281
// the enclosing directory if needed.
282-
func (c *Cacher) makePath(name string) (hash, path string, err error) {
282+
func (c *S3Cacher) makePath(name string) (hash, path string, err error) {
283283
hash = hashName(name)
284284
path = filepath.Join(c.Local, hash[:2], hash)
285285
err = os.MkdirAll(filepath.Dir(path), 0700)
@@ -289,13 +289,13 @@ func (c *Cacher) makePath(name string) (hash, path string, err error) {
289289
return hash, path, err
290290
}
291291

292-
func (c *Cacher) logf(msg string, args ...any) {
292+
func (c *S3Cacher) logf(msg string, args ...any) {
293293
if c.Logf != nil {
294294
c.Logf(msg, args...)
295295
}
296296
}
297297

298-
func (c *Cacher) vlogf(msg string, args ...any) {
298+
func (c *S3Cacher) vlogf(msg string, args ...any) {
299299
if c.LogRequests {
300300
c.logf(msg, args...)
301301
}

0 commit comments

Comments
 (0)