storage

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

Simple file storage powered by badger

Documentation

Overview

Package storage implements disk file operations.

Index

Constants

View Source
const (
	// ErrNoSingleFile returned when does not contain single file in field 'file'
	ErrNoSingleFile = "field 'file' does not contains single item"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DataPath  string `long:"data" default:"var/data" description:"Path to served files"`
	CachePath string `long:"cache" default:"var/cache" description:"Path to cache files"`
}

Config holds all config vars

type File

type File struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	Size      int64     `json:"size"`
	CType     string    `json:"type"`
	Token     string    `json:"token"`
	State     string    `json:"state"`
	SHA1      string    `json:"sha1"`
	CreatedAt time.Time `json:"created_at"`
}

type Service

type Service struct {
	Config *Config
	Log    *log.SugaredLogger
	// contains filtered or unexported fields
}

Service holds upload service

func New

func New(cfg Config, logger *log.SugaredLogger, ps *pubsub.Service) (*Service, error)

New creates an Service object

func (Service) AddFile

func (srv Service) AddFile(token string, file *multipart.FileHeader) (key string, err error)

func (Service) Close

func (srv Service) Close()

func (Service) File

func (srv Service) File(token, id string) (fileMeta *File, filePath string, err error)

func (Service) FileList

func (srv Service) FileList(token string) (files []File, err error)

func (Service) FileStateChange

func (srv Service) FileStateChange(id, state string) error

func (Service) HandlersClose

func (srv Service) HandlersClose()

func (Service) HandlersRun

func (srv Service) HandlersRun()

type UserEvent

type UserEvent struct {
	Type   string `json:"type"`
	FileID string `json:"id"`
	State  string `json:"state"`
}

Jump to

Keyboard shortcuts

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