package memory import ( "context" "forge.cadoles.com/arcad/edge/pkg/app" module "forge.cadoles.com/arcad/edge/pkg/module/app" "github.com/pkg/errors" ) type GetURLFunc func(context.Context, app.ID, string) (string, error) type Repository struct { getURL GetURLFunc apps []*app.Manifest } // GetURL implements app.Repository func (r *Repository) GetURL(ctx context.Context, id app.ID, from string) (string, error) { url, err := r.getURL(ctx, id, from) if err != nil { return "", errors.WithStack(err) } return url, nil } // Get implements app.Repository func (r *Repository) Get(ctx context.Context, id app.ID) (*app.Manifest, error) { for _, app := range r.apps { if app.ID != id { continue } return app, nil } return nil, module.ErrNotFound } // List implements app.Repository func (r *Repository) List(ctx context.Context) ([]*app.Manifest, error) { return r.apps, nil } func NewRepository(getURL GetURLFunc, manifests ...*app.Manifest) *Repository { if manifests == nil { manifests = make([]*app.Manifest, 0) } return &Repository{getURL, manifests} } var _ module.Repository = &Repository{}