1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00

storage: Make type/params configurable for #88

This commit is contained in:
James Hillyerd
2018-03-24 13:18:51 -07:00
parent bb0fb410c1
commit 281cc21412
8 changed files with 53 additions and 18 deletions

View File

@@ -48,11 +48,10 @@ type Store struct {
}
// New creates a new DataStore object using the specified path
func New(cfg config.Storage) storage.Store {
path := cfg.Path
func New(cfg config.Storage) (storage.Store, error) {
path := cfg.Params["path"]
if path == "" {
log.Errorf("No value configured for datastore path")
return nil
return nil, fmt.Errorf("'path' parameter not specified")
}
mailPath := filepath.Join(path, "mail")
if _, err := os.Stat(mailPath); err != nil {
@@ -61,7 +60,7 @@ func New(cfg config.Storage) storage.Store {
log.Errorf("Error creating dir %q: %v", mailPath, err)
}
}
return &Store{path: path, mailPath: mailPath, messageCap: cfg.MailboxMsgCap}
return &Store{path: path, mailPath: mailPath, messageCap: cfg.MailboxMsgCap}, nil
}
// AddMessage adds a message to the specified mailbox.

View File

@@ -265,13 +265,18 @@ func setupDataStore(cfg config.Storage) (*Store, *bytes.Buffer) {
if err != nil {
panic(err)
}
// Capture log output
// Capture log output.
buf := new(bytes.Buffer)
log.SetOutput(buf)
cfg.Path = path
return New(cfg).(*Store), buf
if cfg.Params == nil {
cfg.Params = make(map[string]string)
}
cfg.Params["path"] = path
s, err := New(cfg)
if err != nil {
panic(err)
}
return s.(*Store), buf
}
// deliverMessage creates and delivers a message to the specific mailbox, returning