From 992d3606e5f0c13017d24ce548e0ebdcf49e16ab Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Nov 2024 03:31:52 -0600 Subject: [PATCH] stub in a view interface Signed-off-by: Jeff Carr --- interface.go | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 interface.go diff --git a/interface.go b/interface.go new file mode 100644 index 0000000..4573077 --- /dev/null +++ b/interface.go @@ -0,0 +1,94 @@ +package repolist + +// attempt to make a golang 'interface' for a 'view' of git repos + +import ( + "context" + "errors" + "fmt" + "go.wit.com/lib/protobuf/virtbuf" +) + +// ViewRepoManager is a concrete implementation of the RepoManager interface. +type ViewRepoManager struct { + // client represents a hypothetical API client for interacting with the cloud. + client ViewAPIClient +} + +// ViewAPIClient defines the methods required from the API client. +// This is useful if you want to mock this client for testing. +type ViewAPIClient interface { + GetRepoByName(ctx context.Context, name string) (*virtbuf.NewCluster, error) + StartRepo(ctx context.Context, clusterID string) error + StopRepo(ctx context.Context, clusterID string) error + ListRepos(ctx context.Context) ([]*virtbuf.NewCluster, error) + GetRepoStatus(ctx context.Context, clusterID string) (string, error) +} + +// NewViewRepoManager creates a new ViewRepoManager with the provided API client. +func NewViewRepoManager(client ViewAPIClient) *ViewRepoManager { + return &ViewRepoManager{client: client} +} + +// FindByName retrieves a cluster by name. +func (m *ViewRepoManager) FindByName(ctx context.Context, name string) (*virtbuf.NewCluster, error) { + cluster, err := m.client.GetRepoByName(ctx, name) + if err != nil { + return nil, fmt.Errorf("error finding cluster by name %q: %w", name, err) + } + return cluster, nil +} + +// Start initiates the startup process for the specified cluster. +func (m *ViewRepoManager) Start(ctx context.Context, cluster *virtbuf.NewCluster) error { + if cluster == nil { + return errors.New("cluster cannot be nil") + } + /* + err := m.client.StartRepo(ctx, cluster.Id) + if err != nil { + return fmt.Errorf("error starting cluster %q: %w", cluster.Id, err) + } + */ + return nil +} + +// Stop halts the specified cluster. +func (m *ViewRepoManager) Stop(ctx context.Context, cluster *virtbuf.NewCluster) error { + if cluster == nil { + return errors.New("cluster cannot be nil") + } + /* + err := m.client.StopRepo(ctx, cluster.Id) + if err != nil { + return fmt.Errorf("error stopping cluster %q: %w", cluster.Id, err) + } + */ + return nil +} + +// List retrieves all available clusters. +func (m *ViewRepoManager) List(ctx context.Context) ([]*virtbuf.NewCluster, error) { + /* + clusters, err := m.client.ListRepos(ctx) + if err != nil { + return nil, fmt.Errorf("error listing clusters: %w", err) + } + return clusters, nil + */ + return nil, errors.New("List not done yet") +} + +// Status checks the current status of a specified cluster. +func (m *ViewRepoManager) Status(ctx context.Context, cluster *virtbuf.NewCluster) (string, error) { + if cluster == nil { + return "", errors.New("cluster cannot be nil") + } + /* + status, err := m.client.GetRepoStatus(ctx, cluster.Id) + if err != nil { + return "", fmt.Errorf("error getting status of cluster %q: %w", cluster.Id, err) + } + */ + return "", nil +}