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

@@ -3,9 +3,12 @@ package storage
import (
"errors"
"fmt"
"io"
"net/mail"
"time"
"github.com/jhillyerd/inbucket/pkg/config"
)
var (
@@ -14,6 +17,9 @@ var (
// ErrNotWritable indicates the message is closed; no longer writable
ErrNotWritable = errors.New("Message not writable")
// Constructors tracks registered storage constructors
Constructors = make(map[string]func(config.Storage) (Store, error))
)
// Store is the interface Inbucket uses to interact with storage implementations.
@@ -38,3 +44,11 @@ type Message interface {
Source() (io.ReadCloser, error)
Size() int64
}
// FromConfig creates an instance of the Store based on the provided configuration.
func FromConfig(c config.Storage) (store Store, err error) {
if cf := Constructors[c.Type]; cf != nil {
return cf(c)
}
return nil, fmt.Errorf("unknown storage type configured: %q", c.Type)
}