versions

package module
v0.0.0-...-8559ee1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: MIT Imports: 14 Imported by: 0

README

versions

A versions management service and CLI

Go Report Card godoc license Coverage Build Status

Documentation

Index

Constants

View Source
const (
	StorageTypeLocal  = "local"
	StorageTypeGithub = "github"
	StorageTypeS3     = "s3"
)

Variables

View Source
var (
	ErrVersionNotFound    = errors.New("versions.not_found")
	ErrVersionExists      = errors.New("versions.exists")
	ErrVersionIsNil       = errors.New("versions.version.is_nil")
	ErrVersionMissingOS   = errors.New("versions.missing.os")
	ErrVersionMissingArch = errors.New("versions.missing.arch")

	ErrVersionInvalidId            = errors.New("versions.invalid.id")
	ErrVersionMissingId            = errors.New("versions.missing.id")
	ErrVersionIdNotEmpty           = errors.New("versions.invalid.id_not_empty")
	ErrVersionMissingApplication   = errors.New("versions.missing.application")
	ErrVersionMissingApplicationId = errors.New("versions.missing.application_id")
	ErrVersionMissingComponents    = errors.New("versions.missing.major_minor_and_revision")

	ErrApplicationExists      = errors.New("versions.application.exists")
	ErrApplicationMissingId   = errors.New("versions.application.missing.id")
	ErrApplicationMissingName = errors.New("versions.application.missing.name")
	ErrApplicationNotFound    = errors.New("versions.application.not_found")

	ErrStorageInvalidType = errors.New("versions.storage.invalid_type")

	ErrDownloadExists             = errors.New("versions.download.exists")
	ErrDownloadNotFound           = errors.New("versions.download.not_found")
	ErrDownloadStorageTypeMissing = errors.New("versions.download.storage_type.missing")

	ErrDownloadDataIsNil        = errors.New("versions.download.data.is_nil")
	ErrDownloadFilenameMissing  = errors.New("versions.download.filename.missing")
	ErrDownloadIdMissing        = errors.New("versions.download.id.missing")
	ErrDownloadVersionIdMissing = errors.New("versions.download.verision_id.missing")
	ErrDownloadFileNotFound     = errors.New("versions.download.file.not_found")
)

Functions

func AddStorage

func AddStorage(storageType string, storage Storage) error

func ApplicationsToProtos

func ApplicationsToProtos(list []Application) []*pb.Application

func DownloadsToProtos

func DownloadsToProtos(list []Download) []*pb.Download

func ErrApplicationIdInvalidCharacter

func ErrApplicationIdInvalidCharacter(char string) error

func NewLocalStorage

func NewLocalStorage(storagePath ...string) (*localStorage, error)

func Parse

func Parse(ver string) (string, string, string)

func Sha1ToString

func Sha1ToString(in []byte) string

func Sha256ToString

func Sha256ToString(in []byte) string

func VersionsToProtos

func VersionsToProtos(list []Version) []*pb.Version

Types

type Application

type Application struct {
	Id   string `json:"id"`
	Name string `json:"name"`

	UpdatedAt time.Time `json:"updated_at"`
	CreatedAt time.Time `json:"created_at"`
}

func ApplicationFromProto

func ApplicationFromProto(proto *pb.Application) Application

func (*Application) ToProto

func (a *Application) ToProto() *pb.Application

func (*Application) Validate

func (a *Application) Validate() (bool, error)

type Download

type Download struct {
	Id          int    `json:"id"`
	VersionId   int    `json:"version_id"`
	StorageType string `json:"storage_type"`
	ContentType string `json:"content_type"`
	Filename    string `json:"filename"`
	Ext         string `json:"ext"`
	Format      string `json:"format"`
	Protocol    string `json:"protocol"`
	OS          string `json:"os"`
	Arch        string `json:"arch"`

	SHA1   string `json:"sha1"`
	SHA256 string `json:"sha256"`

	Downloads int `json:"total_downloads"`

	UpdatedAt time.Time `json:"updated_at"`
	CreatedAt time.Time `json:"created_at"`

	Data []byte `json:"-"`
}

func DownloadFromProto

func DownloadFromProto(proto *pb.Download) Download

func (*Download) GetFile

func (d *Download) GetFile() ([]byte, error)

func (*Download) ToProto

func (d *Download) ToProto() *pb.Download

func (*Download) Validate

func (d *Download) Validate() (bool, error)

type Storage

type Storage interface {
	Save(int, *Download) error
	Get(*Download) ([]byte, error)
}

func GetStorage

func GetStorage(storageType string) (Storage, error)

type Store

type Store interface {
	Type() string
	Migrations() error

	Create(*Version) error
	Update(*Version) error
	Delete(id int) error
	GetById(id int) (Version, error)

	// Get returns the version(s) for an application ID.
	// options:
	//   opts[0] > 0 = limit
	//   opts[1] > 0 = offset
	GetByApplication(appId string, opts ...int) ([]Version, error)

	Exists(*Version) bool

	// GetLatest returns the latest version for an application ID.
	// options:
	//   opts[0] > 0 = stable only
	GetLatest(appId string, opts ...int) (Version, error)

	ApplicationExists(*Application) bool

	CreateApplication(*Application) error
	UpdateApplication(*Application) error
	DeleteApplication(id string) error
	GetApplicationById(id string) (Application, error)
	GetApplications(opts ...int) ([]Application, error)

	DownloadExists(*Download) bool

	CreateDownload(*Download) error
	UpdateDownload(*Download) error
	DeleteDownload(id int) error
	GetDownloadById(id int) (Download, error)
	GetDownloads(opts ...int) ([]Download, error)
}

func NewStore

func NewStore(storeType string) (Store, error)

type Version

type Version struct {
	Id       int    `json:"id"`
	Major    string `json:"major"`
	Minor    string `json:"minor"`
	Revision string `json:"revision"`

	ApplicationId string `json:"application_id"`
	Name          string `json:"name"`
	Stable        bool   `json:"stable"`

	Downloads []Download `json:"downloads"`

	UpdatedAt time.Time `json:"updated_at"`
	CreatedAt time.Time `json:"created_at"`
}

func FromProto

func FromProto(proto *pb.Version) Version

func (*Version) Full

func (v *Version) Full() string

func (*Version) ToProto

func (v *Version) ToProto() *pb.Version

func (*Version) Validate

func (v *Version) Validate() (bool, error)

Validate confirms the Version is sufficient for entry into the store

returns:
  - valid/ok (bool)
  - error (error)

Directories

Path Synopsis
cmd
cli
Package versions is a reverse proxy.
Package versions is a reverse proxy.

Jump to

Keyboard shortcuts

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