diff --git a/pkg/download/protocol.go b/pkg/download/protocol.go index 901cb5e0..b59a9cf1 100644 --- a/pkg/download/protocol.go +++ b/pkg/download/protocol.go @@ -54,7 +54,7 @@ func New(opts *Opts, wrappers ...Wrapper) Protocol { } type protocol struct { - s storage.Backend + storage storage.Backend stasher stash.Stasher lister UpstreamLister } @@ -64,7 +64,7 @@ func (p *protocol) List(ctx context.Context, mod string) ([]string, error) { ctx, span := observ.StartSpan(ctx, op.String()) defer span.End() - strList, sErr := p.s.List(ctx, mod) + strList, sErr := p.storage.List(ctx, mod) // if we got an unexpected storage err then we can not guarantee that the end result contains all versions // a tag or repo could have been deleted if sErr != nil { @@ -103,13 +103,13 @@ func (p *protocol) Info(ctx context.Context, mod, ver string) ([]byte, error) { const op errors.Op = "protocol.Info" ctx, span := observ.StartSpan(ctx, op.String()) defer span.End() - info, err := p.s.Info(ctx, mod, ver) + info, err := p.storage.Info(ctx, mod, ver) if errors.IsNotFoundErr(err) { err = p.stasher.Stash(ctx, mod, ver) if err != nil { return nil, errors.E(op, err) } - info, err = p.s.Info(ctx, mod, ver) + info, err = p.storage.Info(ctx, mod, ver) } if err != nil { return nil, errors.E(op, err) @@ -122,13 +122,13 @@ func (p *protocol) GoMod(ctx context.Context, mod, ver string) ([]byte, error) { const op errors.Op = "protocol.GoMod" ctx, span := observ.StartSpan(ctx, op.String()) defer span.End() - goMod, err := p.s.GoMod(ctx, mod, ver) + goMod, err := p.storage.GoMod(ctx, mod, ver) if errors.IsNotFoundErr(err) { err = p.stasher.Stash(ctx, mod, ver) if err != nil { return nil, errors.E(op, err) } - goMod, err = p.s.GoMod(ctx, mod, ver) + goMod, err = p.storage.GoMod(ctx, mod, ver) } if err != nil { return nil, errors.E(op, err) @@ -141,13 +141,13 @@ func (p *protocol) Zip(ctx context.Context, mod, ver string) (io.ReadCloser, err const op errors.Op = "protocol.Zip" ctx, span := observ.StartSpan(ctx, op.String()) defer span.End() - zip, err := p.s.Zip(ctx, mod, ver) + zip, err := p.storage.Zip(ctx, mod, ver) if errors.IsNotFoundErr(err) { err = p.stasher.Stash(ctx, mod, ver) if err != nil { return nil, errors.E(op, err) } - zip, err = p.s.Zip(ctx, mod, ver) + zip, err = p.storage.Zip(ctx, mod, ver) } if err != nil { return nil, errors.E(op, err) diff --git a/pkg/stash/stasher.go b/pkg/stash/stasher.go index 8c7e1c52..af2a60e8 100644 --- a/pkg/stash/stasher.go +++ b/pkg/stash/stasher.go @@ -33,8 +33,8 @@ func New(f module.Fetcher, s storage.Backend, wrappers ...Wrapper) Stasher { } type stasher struct { - f module.Fetcher - s storage.Backend + fetcher module.Fetcher + storage storage.Backend } func (s *stasher) Stash(ctx context.Context, mod, ver string) error { @@ -52,7 +52,7 @@ func (s *stasher) Stash(ctx context.Context, mod, ver string) error { return errors.E(op, err) } defer v.Zip.Close() - err = s.s.Save(ctx, mod, ver, v.Mod, v.Zip, v.Info) + err = s.storage.Save(ctx, mod, ver, v.Mod, v.Zip, v.Info) if err != nil { return errors.E(op, err) } @@ -61,7 +61,7 @@ func (s *stasher) Stash(ctx context.Context, mod, ver string) error { func (s *stasher) fetchModule(ctx context.Context, mod, ver string) (*storage.Version, error) { const op errors.Op = "stasher.fetchModule" - v, err := s.f.Fetch(ctx, mod, ver) + v, err := s.fetcher.Fetch(ctx, mod, ver) if err != nil { return nil, errors.E(op, err) } diff --git a/pkg/stash/with_pool.go b/pkg/stash/with_pool.go index f5a65afe..63d11dce 100644 --- a/pkg/stash/with_pool.go +++ b/pkg/stash/with_pool.go @@ -8,7 +8,7 @@ import ( ) type withpool struct { - s Stasher + stasher Stasher // see download/addons/with_pool // for design docs on about this channel. @@ -20,8 +20,8 @@ type withpool struct { func WithPool(numWorkers int) Wrapper { return func(s Stasher) Stasher { st := &withpool{ - s: s, - jobCh: make(chan func()), + stasher: s, + jobCh: make(chan func()), } st.start(numWorkers) return st @@ -47,7 +47,7 @@ func (s *withpool) Stash(ctx context.Context, mod, ver string) error { var err error done := make(chan struct{}, 1) s.jobCh <- func() { - err = s.s.Stash(ctx, mod, ver) + err = s.stasher.Stash(ctx, mod, ver) close(done) } <-done diff --git a/pkg/stash/with_singleflight.go b/pkg/stash/with_singleflight.go index 08f0ab34..f0109a5c 100644 --- a/pkg/stash/with_singleflight.go +++ b/pkg/stash/with_singleflight.go @@ -16,14 +16,14 @@ import ( // response to both the first and the second client. func WithSingleflight(s Stasher) Stasher { sf := &withsf{} - sf.s = s + sf.stasher = s sf.subs = map[string][]chan error{} return sf } type withsf struct { - s Stasher + stasher Stasher mu sync.Mutex subs map[string][]chan error @@ -31,7 +31,7 @@ type withsf struct { func (s *withsf) process(ctx context.Context, mod, ver string) { mv := config.FmtModVer(mod, ver) - err := s.s.Stash(ctx, mod, ver) + err := s.stasher.Stash(ctx, mod, ver) s.mu.Lock() defer s.mu.Unlock() for _, ch := range s.subs[mv] {