2013-08-06 03:51:26 +00:00
|
|
|
package dbutil
|
2013-02-09 04:43:39 +00:00
|
|
|
|
|
|
|
import (
|
2017-04-07 15:56:05 +00:00
|
|
|
"io"
|
|
|
|
|
2013-05-09 16:13:46 +00:00
|
|
|
"github.com/vbatts/imgsrv/types"
|
2013-02-09 04:43:39 +00:00
|
|
|
)
|
|
|
|
|
2017-04-07 15:32:39 +00:00
|
|
|
// Handles are all the register backing Handlers
|
2017-04-07 17:29:07 +00:00
|
|
|
var Handles = map[string]Handler{}
|
2013-10-04 02:49:57 +00:00
|
|
|
|
2017-04-07 15:32:39 +00:00
|
|
|
// Handler is the means of getting "files" from the backing database
|
|
|
|
type Handler interface {
|
2017-04-07 17:29:07 +00:00
|
|
|
Init(config []byte, err error) error
|
2017-04-07 15:32:39 +00:00
|
|
|
Close() error
|
2013-09-10 18:51:44 +00:00
|
|
|
|
2017-04-07 15:56:05 +00:00
|
|
|
Open(filename string) (File, error)
|
|
|
|
Create(filename string) (File, error)
|
2017-04-07 15:32:39 +00:00
|
|
|
Remove(filename string) error
|
2013-08-06 00:29:16 +00:00
|
|
|
|
2017-04-07 15:32:39 +00:00
|
|
|
//HasFileByMd5(md5 string) (exists bool, err error)
|
|
|
|
//HasFileByKeyword(keyword string) (exists bool, err error)
|
|
|
|
HasFileByFilename(filename string) (exists bool, err error)
|
|
|
|
FindFilesByKeyword(keyword string) (files []types.File, err error)
|
|
|
|
FindFilesByMd5(md5 string) (files []types.File, err error)
|
|
|
|
FindFilesByPatt(filenamePat string) (files []types.File, err error)
|
2013-08-06 00:29:16 +00:00
|
|
|
|
2017-04-07 15:32:39 +00:00
|
|
|
CountFiles(filename string) (int, error)
|
2013-08-06 00:29:16 +00:00
|
|
|
|
2017-04-07 15:32:39 +00:00
|
|
|
GetFiles(limit int) (files []types.File, err error)
|
|
|
|
GetFileByFilename(filename string) (types.File, error)
|
|
|
|
GetExtensions() (kp []types.IdCount, err error)
|
|
|
|
GetKeywords() (kp []types.IdCount, err error)
|
2013-08-06 00:29:16 +00:00
|
|
|
}
|
2017-04-07 15:56:05 +00:00
|
|
|
|
2017-04-07 17:29:07 +00:00
|
|
|
// File is what is stored and fetched from the backing database
|
2017-04-07 15:56:05 +00:00
|
|
|
type File interface {
|
|
|
|
io.Reader
|
|
|
|
io.Writer
|
|
|
|
io.Closer
|
|
|
|
MetaDataer
|
|
|
|
}
|
2017-04-07 17:29:07 +00:00
|
|
|
|
|
|
|
// MetaDataer allows set/get for optional metadata
|
|
|
|
type MetaDataer interface {
|
|
|
|
/*
|
|
|
|
GetMeta unmarshals the optional "metadata" field associated with the file into
|
|
|
|
the result parameter. The meaning of keys under that field is user-defined. For
|
|
|
|
example:
|
|
|
|
|
|
|
|
result := struct{ INode int }{}
|
|
|
|
err = file.GetMeta(&result)
|
|
|
|
if err != nil {
|
|
|
|
panic(err.String())
|
|
|
|
}
|
|
|
|
fmt.Printf("inode: %d\n", result.INode)
|
|
|
|
*/
|
|
|
|
GetMeta(result interface{}) (err error)
|
|
|
|
/*
|
|
|
|
SetMeta changes the optional "metadata" field associated with the file. The
|
|
|
|
meaning of keys under that field is user-defined. For example:
|
|
|
|
|
|
|
|
file.SetMeta(bson.M{"inode": inode})
|
|
|
|
|
|
|
|
It is a runtime error to call this function when the file is not open for
|
|
|
|
writing.
|
|
|
|
|
|
|
|
*/
|
|
|
|
SetMeta(metadata interface{})
|
|
|
|
}
|