1
0
Fork 0
mirror of https://github.com/vbatts/imgsrv.git synced 2025-07-29 02:10:29 +00:00

dbutil: abstract out the last mongo type

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2017-04-07 11:56:05 -04:00
parent efa8ac6511
commit b80d34f423
Signed by: vbatts
GPG key ID: 10937E57733F1362
3 changed files with 31 additions and 23 deletions

View file

@ -1,8 +1,9 @@
package dbutil
import (
"io"
"github.com/vbatts/imgsrv/types"
"labix.org/v2/mgo"
)
// Handles are all the register backing Handlers
@ -13,8 +14,8 @@ type Handler interface {
Init(config interface{}) error
Close() error
Open(filename string) (*mgo.GridFile, error)
Create(filename string) (*mgo.GridFile, error)
Open(filename string) (File, error)
Create(filename string) (File, error)
Remove(filename string) error
//HasFileByMd5(md5 string) (exists bool, err error)
@ -31,3 +32,15 @@ type Handler interface {
GetExtensions() (kp []types.IdCount, err error)
GetKeywords() (kp []types.IdCount, err error)
}
type MetaDataer interface {
GetMeta(result interface{}) (err error)
SetMeta(metadata interface{})
}
type File interface {
io.Reader
io.Writer
io.Closer
MetaDataer
}

View file

@ -59,12 +59,12 @@ func (h mongoHandle) Close() error {
}
// pass through for GridFs
func (h mongoHandle) Open(filename string) (file *mgo.GridFile, err error) {
func (h mongoHandle) Open(filename string) (file dbutil.File, err error) {
return h.Gfs.Open(strings.ToLower(filename))
}
// pass through for GridFs
func (h mongoHandle) Create(filename string) (file *mgo.GridFile, err error) {
func (h mongoHandle) Create(filename string) (file dbutil.File, err error) {
return h.Gfs.Create(strings.ToLower(filename))
}