Documentation ¶
Overview ¶
Package store provides a storage plugin for sent letters.
Example ¶
package main import ( "context" "github.com/bounoable/postdog" "github.com/bounoable/postdog/letter" "github.com/bounoable/postdog/plugin/store" "github.com/bounoable/postdog/plugin/store/memorystore" ) func main() { po := postdog.New( postdog.WithPlugin( store.Plugin( memorystore.New(), // in-memory store ), ), ) err := po.Send(context.Background(), letter.Write( letter.Text("Hello."), )) _ = err }
Output:
Example (Disable) ¶
package main import ( "context" "github.com/bounoable/postdog" "github.com/bounoable/postdog/letter" "github.com/bounoable/postdog/plugin/store" "github.com/bounoable/postdog/plugin/store/memorystore" ) func main() { po := postdog.New( postdog.WithPlugin( store.Plugin( memorystore.New(), // in-memory store ), ), ) // disable storage for this context ctx := store.Disable(context.Background()) err := po.Send(ctx, letter.Write( letter.Text("Hello."), )) _ = err }
Output:
Example (Query) ¶
package main import ( "context" "fmt" "time" "github.com/bounoable/postdog" "github.com/bounoable/postdog/plugin/store" "github.com/bounoable/postdog/plugin/store/memorystore" "github.com/bounoable/postdog/plugin/store/query" ) func main() { memstore := memorystore.New( /* fill the store with letters */ ) // in-memory store _ = postdog.New( postdog.WithPlugin(store.Plugin(memstore)), ) ctx := context.Background() cur, err := query.Run( ctx, memstore, query.Subject("order", "offer"), // subject must contain "order" or "offer" query.SentBetween(time.Now().AddDate(0, 0, -7), time.Now()), // letter must have been sent in the past 7 days query.Sort(query.SortBySendDate, query.SortDesc), // sort descending by send date // see the `query` package for more query options ) if err != nil { panic(err) } defer cur.Close(ctx) // close the cursor after use for cur.Next(ctx) { let := cur.Current() fmt.Println(let) } if cur.Err() != nil { panic(cur.Err()) } }
Output:
Index ¶
- Variables
- func AutowirePlugin(ctx context.Context, cfg map[string]interface{}) (postdog.Plugin, error)
- func Disable(ctx context.Context) context.Context
- func Disabled(ctx context.Context) bool
- func Enable(ctx context.Context) context.Context
- func Enabled(ctx context.Context) bool
- func Plugin(store Store) postdog.PluginFunc
- func Register(cfg *autowire.Config)
- func RegisterProvider(name string, factory Factory)
- type Factory
- type FactoryFunc
- type Letter
- type Store
- type UnregisteredProviderError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
// Name is the plugin name.
Name = "store"
)
Functions ¶
func AutowirePlugin ¶ added in v0.4.0
AutowirePlugin creates the store plugin from the given cfg.
func Plugin ¶
func Plugin(store Store) postdog.PluginFunc
Plugin is the install function for the store plugin. It hooks into the postdog.AfterSend hook and inserts all sent letters into the store implementation.
func RegisterProvider ¶ added in v0.4.0
RegisterProvider globally registers the store factory for the given store provider name for autowiring.
Types ¶
type FactoryFunc ¶ added in v0.4.0
FactoryFunc allows functions to be used as a Factory.
func (FactoryFunc) CreateStore ¶ added in v0.4.0
CreateStore creates the store from the given cfg.
type UnregisteredProviderError ¶ added in v0.4.0
type UnregisteredProviderError struct {
Name string
}
UnregisteredProviderError means the autowire config defines the plugin with an unregistered store provider name.
func (UnregisteredProviderError) Error ¶ added in v0.4.0
func (err UnregisteredProviderError) Error() string
Directories ¶
Path | Synopsis |
---|---|
Package mock_store is a generated GoMock package.
|
Package mock_store is a generated GoMock package. |
Package mongostore provides the mongodb store implementation.
|
Package mongostore provides the mongodb store implementation. |
Package query provides functions to query letters from a store.
|
Package query provides functions to query letters from a store. |
mock_query
Package mock_query is a generated GoMock package.
|
Package mock_query is a generated GoMock package. |
Package storetest provides testing utilities that can be used to test store implementations.
|
Package storetest provides testing utilities that can be used to test store implementations. |
Click to show internal directories.
Click to hide internal directories.