db

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package db contains methods to store files on filesystem and metadata in database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GCMonitor

func GCMonitor(ch <-chan *Item, closed chan struct{}, db *sql.DB, li, le *log.Logger, period time.Duration)

GCMonitor is garbage collection monitoring to delete expired by date or counter items.

func InTransaction added in v1.2.0

func InTransaction(db *sql.DB, f func(tx *sql.Tx) error) error

InTransaction runs method f and does commit or rollback.

func IsNameHash

func IsNameHash(name string) bool

IsNameHash checks name can be an encrypted file name.

func Key

func Key(secret string, salt []byte) ([]byte, []byte)

Key calculates and returns secret key and its SHA512 hash.

Types

type Item

type Item struct {
	ID      int64
	Name    string
	Path    string
	Salt    string
	Hash    string
	Counter int
	Created time.Time
	Expired time.Time
}

Item is base data struct for incoming data.

func Read

func Read(db *sql.DB, hash string, le *log.Logger) (*Item, error)

Read reads an item by its hash from database.

func (*Item) ContentType

func (item *Item) ContentType() string

ContentType returns string content-type for stored file.

func (*Item) Decrement

func (item *Item) Decrement(db *sql.DB, le *log.Logger) (bool, error)

Decrement updates items' counter. The first returned parameter is "updated" flags.

func (*Item) Decrypt

func (item *Item) Decrypt(w io.Writer, key []byte, l *log.Logger) error

Decrypt decrypts item related file and writes result to w.

func (*Item) Delete

func (item *Item) Delete(db *sql.DB, le *log.Logger) error

Delete removes items from database and related file from file system.

func (*Item) Encrypt

func (item *Item) Encrypt(inFile io.Reader, secret string, l *log.Logger) error

Encrypt encrypts source file and fills the item by result.

func (*Item) FullPath

func (item *Item) FullPath() string

FullPath return full path for item's file.

func (*Item) GetURL

func (item *Item) GetURL(r *http.Request, secure bool) *url.URL

GetURL returns item's URL.

func (*Item) IsFileExists

func (item *Item) IsFileExists() bool

IsFileExists checks item's related file exists.

func (*Item) IsValidSecret

func (item *Item) IsValidSecret(secret string) ([]byte, error)

IsValidSecret checks the secret.

func (*Item) Save

func (item *Item) Save(db *sql.DB) error

Save saves the item to database.

Jump to

Keyboard shortcuts

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