datastore

package
v0.0.0-...-3a6673b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package datastore implements the database backend classes required by the GoatCheese application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Datastore

type Datastore interface {
	// AllRepositories returns a slice of all repositories defined in the data store.
	AllRepositories() ([]Repository, error)
	// GetRepository returns the Repository for a given name.
	GetRepository(repositoryName string) (Repository, error)
	// Close closes the database connection
	Close() error
}

Datastore defines the main interface for the data store.

A data store is a combination of a database and a storage path on the disk. It stores the metadata of the different repositories and projects in the database and the files to download in the storage path on disk.

func New

func New(configFile string) (Datastore, error)

New creates a new data store object and set's up the database if required. It reads the configuration options and repositories to setup from a configuration file, which's path is given by the `configFile` parameter.

Warning: The data store is a global singleton and thus, this method should only be called once!

type Project

type Project interface {
	Name() string                                     // Name returns the name of the project
	ProjectPath() string                              // ProjectPath returns the path on the data storage
	ProjectFiles() ([]ProjectFile, error)             // ProjectFiles returns a slice of all files contained
	GetFile(fileName string) (ProjectFile, error)     // GetFile returns a single file given it's file name
	AddFile(fileName string, content io.Reader) error // AddFile adds a new file to the project
}

Project defines the interface of a project in the GoatCheese shop. It defines, that a project needs to have the following properties:

- Name - ProjectPath - ProjectFiles

Additionally, it defines, that project files can be added to a project and, given a filename one can get a specific project file from it.

type ProjectFile

type ProjectFile interface {
	Name() string                      // Name returns the name of the project file
	Checksum() string                  // Checksum returns the checksum of the file
	SetChecksum(checksum string) error // SetChecksum sets the checksum of the project file
	IsLocked() bool                    // IsLocked checks whether this file is currently locked by another thread
	Lock() error                       // Lock locks this project file for writing or deletion
	Unlock() error                     // Unlock unlocks this project file for the other threads
	FilePath() string                  // FilePath returns the file path of the project file on the data storage
	Write(content io.Reader) error     // Write writes the contents from the given io.Reader to the file
	Delete() error                     // Delete deletes the project file from the database
}

ProjectFile defines the required methods of a project file. It defines that a project file needs to have the following properties:

- Name - Checksum - FilePath - Lock

Additionally, a file needs to be lockable, can be written and deleted.

type Repository

type Repository interface {
	// Name returns the name of the repository
	Name() string
	// Bases returns the slice of base repositories
	Bases() ([]Repository, error)
	// AllProjects returns a slice of all projects defined
	// in all reachable repositories
	AllProjects() ([]Project, error)
	// RepositoryPath returns the storage path of the repository
	RepositoryPath() string
	// AddProject adds a new project to this repository
	AddProject(projectName string) (Project, error)
	// GetProject returns a project given its project name
	GetProject(projectName string) (Project, error)
	// StoragePath returns the storage base path for all repositories
	StoragePath() string
	// SetBases sets the slice of base repositories for this repository
	SetBases(baseRepositories []Repository) error
}

Repository defines the interface of a repository for the GoatCheese shop.

A repository needs to have a name, a list of projects and a storage path. Additionally, to implement inheritance, it contains a slice of base repositories. These repositories are requested, if a project is not found in the repository itself.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL