mirror of
https://github.com/vbatts/imgsrv.git
synced 2024-11-27 02:25:41 +00:00
*: fixes to be working on new abstractions
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
b80d34f423
commit
610cd418ca
3 changed files with 43 additions and 10 deletions
|
@ -7,11 +7,11 @@ import (
|
|||
)
|
||||
|
||||
// Handles are all the register backing Handlers
|
||||
var Handles map[string]Handler
|
||||
var Handles = map[string]Handler{}
|
||||
|
||||
// Handler is the means of getting "files" from the backing database
|
||||
type Handler interface {
|
||||
Init(config interface{}) error
|
||||
Init(config []byte, err error) error
|
||||
Close() error
|
||||
|
||||
Open(filename string) (File, error)
|
||||
|
@ -33,14 +33,38 @@ type Handler interface {
|
|||
GetKeywords() (kp []types.IdCount, err error)
|
||||
}
|
||||
|
||||
type MetaDataer interface {
|
||||
GetMeta(result interface{}) (err error)
|
||||
SetMeta(metadata interface{})
|
||||
}
|
||||
|
||||
// File is what is stored and fetched from the backing database
|
||||
type File interface {
|
||||
io.Reader
|
||||
io.Writer
|
||||
io.Closer
|
||||
MetaDataer
|
||||
}
|
||||
|
||||
// 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{})
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package mongo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/vbatts/imgsrv/dbutil"
|
||||
|
@ -29,8 +30,15 @@ type mongoHandle struct {
|
|||
Gfs *mgo.GridFS
|
||||
}
|
||||
|
||||
func (h *mongoHandle) Init(config interface{}) (err error) {
|
||||
h.config = config.(dbConfig)
|
||||
func (h *mongoHandle) Init(config []byte, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h.config = dbConfig{}
|
||||
if err := json.Unmarshal(config, &h.config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h.Session, err = mgo.Dial(h.config.Seed)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
@ -45,7 +46,7 @@ func runServer(c *config.Config) {
|
|||
serverConfig.MongoDbName,
|
||||
}
|
||||
|
||||
if err := du.Init(duConfig); err != nil {
|
||||
if err := du.Init(json.Marshal(duConfig)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer du.Close() // TODO this ought to catch a signal to cleanup
|
||||
|
|
Loading…
Reference in a new issue