mirror of
https://github.com/gomods/athens
synced 2026-02-03 12:10:32 +00:00
implement /index endpoint (#1630)
* implement /index endpoint * rename to Module to Path
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gomods/athens/pkg/errors"
|
||||
"github.com/gomods/athens/pkg/index"
|
||||
"github.com/gomods/athens/pkg/log"
|
||||
"github.com/gomods/athens/pkg/module"
|
||||
"github.com/gomods/athens/pkg/observ"
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
// Stasher has the job of taking a module
|
||||
// from an upstream entity and stashing it to a Storage Backend.
|
||||
// from an upstream entity and stashing it to a Storage Backend and Index.
|
||||
// It also returns a string that represents a semver version of
|
||||
// what was requested, this is helpful if what was requested
|
||||
// was a descriptive version such as a branch name or a full commit sha.
|
||||
@@ -27,8 +28,8 @@ type Wrapper func(Stasher) Stasher
|
||||
// New returns a plain stasher that takes
|
||||
// a module from a download.Protocol and
|
||||
// stashes it into a backend.Storage.
|
||||
func New(f module.Fetcher, s storage.Backend, wrappers ...Wrapper) Stasher {
|
||||
var st Stasher = &stasher{f, s, storage.WithChecker(s)}
|
||||
func New(f module.Fetcher, s storage.Backend, indexer index.Indexer, wrappers ...Wrapper) Stasher {
|
||||
var st Stasher = &stasher{f, s, storage.WithChecker(s), indexer}
|
||||
for _, w := range wrappers {
|
||||
st = w(st)
|
||||
}
|
||||
@@ -40,6 +41,7 @@ type stasher struct {
|
||||
fetcher module.Fetcher
|
||||
storage storage.Backend
|
||||
checker storage.Checker
|
||||
indexer index.Indexer
|
||||
}
|
||||
|
||||
func (s *stasher) Stash(ctx context.Context, mod, ver string) (string, error) {
|
||||
@@ -71,6 +73,10 @@ func (s *stasher) Stash(ctx context.Context, mod, ver string) (string, error) {
|
||||
if err != nil {
|
||||
return "", errors.E(op, err)
|
||||
}
|
||||
err = s.indexer.Index(ctx, mod, v.Semver)
|
||||
if err != nil {
|
||||
return "", errors.E(op, err)
|
||||
}
|
||||
return v.Semver, nil
|
||||
}
|
||||
|
||||
@@ -80,6 +86,5 @@ func (s *stasher) fetchModule(ctx context.Context, mod, ver string) (*storage.Ve
|
||||
if err != nil {
|
||||
return nil, errors.E(op, err)
|
||||
}
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user