edge/pkg/module/app/memory/repository.go
William Petit b5b4042cc7
All checks were successful
arcad/edge/pipeline/head This commit looks good
feat(sdk,client): add menu to help navigation between apps
2023-04-20 10:17:37 +02:00

55 lines
1.1 KiB
Go

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{}