Documentation ¶
Overview ¶
Package query provides functions to query letters from a store.
Index ¶
- Constants
- type AttachmentFilter
- type AttachmentSizeFilter
- type Cursor
- type Option
- func AttachmentContentType(ct ...string) Option
- func AttachmentName(n ...string) Option
- func AttachmentSize(s ...int) Option
- func AttachmentSizeRange(min, max int) Option
- func BCC(bcc ...string) Option
- func CC(cc ...string) Option
- func From(f ...string) Option
- func SentAfter(t time.Time) Option
- func SentBefore(t time.Time) Option
- func SentBetween(l, r time.Time) Option
- func SentInBetween(l, r time.Time) Option
- func Sort(by Sorting, dir SortDirection) Option
- func Subject(s ...string) Option
- func To(to ...string) Option
- type Query
- type Repository
- type SentAtFilter
- type SortConfig
- type SortDirection
- type Sorting
Examples ¶
Constants ¶
const ( // SortAsc sorts letters in ascending order. SortAsc = SortDirection(iota) // SortDesc sorts letters in descending order. SortDesc )
const ( // SortBySendDate sorts letters by the "SentAt" field. SortBySendDate = Sorting(iota) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttachmentFilter ¶
type AttachmentFilter struct { Names []string ContentTypes []string Size AttachmentSizeFilter }
AttachmentFilter filters letters by their attachments.
type AttachmentSizeFilter ¶
AttachmentSizeFilter filters letters by their attachment sizes.
type Cursor ¶
type Cursor interface { Next(context.Context) bool Current() store.Letter Close(context.Context) error Err() error }
Cursor is used to iterate over a stream of letters.
func Run ¶
Run builds and runs a query against repo. Use opts to configure the query.
Example ¶
package main import ( "context" "fmt" "github.com/bounoable/postdog/letter" "github.com/bounoable/postdog/plugin/store" "github.com/bounoable/postdog/plugin/store/memorystore" "github.com/bounoable/postdog/plugin/store/query" ) func main() { // Usually this would be a persistent implementation repo := memorystore.New( store.Letter{Letter: letter.Write(letter.Subject("Letter 1"))}, store.Letter{Letter: letter.Write(letter.Subject("Letter 2"))}, ) cur, err := query.Run( context.Background(), repo, query.Subject("Letter"), // sender name / address must contain "Letter" query.Sort(query.SortBySendDate, query.SortDesc), // sort descending by send date // more query options ... ) defer cur.Close(context.Background()) if err != nil { panic(err) } for cur.Next(context.Background()) { let := cur.Current() fmt.Println(let) } if cur.Err() != nil { panic(cur.Err()) } }
Output:
type Option ¶
type Option func(*Query)
Option is a query option.
func AttachmentContentType ¶
AttachmentContentType includes only letters that have an attachment whose "Content-Type" header contains ct.
func AttachmentName ¶
AttachmentName includes only letters that have an attachment whose name contains n.
func AttachmentSize ¶
AttachmentSize includes only letters that have an attachment whose filesize is exactly s.
func AttachmentSizeRange ¶
AttachmentSizeRange includes only letters that have an attachment whose filesize is in the range [min, max].
func SentBefore ¶
SentBefore includes only letters which have been sent before t.
func SentBetween ¶
SentBetween includes only letters which have been sent between [l, r].
func SentInBetween ¶
SentInBetween includes only letters which have been sent between (l, r).
func Sort ¶
func Sort(by Sorting, dir SortDirection) Option
Sort configures the sorting of the letters.
type Query ¶
type Query struct { SentAt SentAtFilter Subjects []string From []string To []string CC []string BCC []string Attachment AttachmentFilter Sort SortConfig }
Query defines the filters and options for a query.
type Repository ¶
Repository is the query repository.
type SentAtFilter ¶
SentAtFilter filters letters by their send date.
type SortConfig ¶
type SortConfig struct { SortBy Sorting Dir SortDirection }
SortConfig defines the sorting of queried letters.
Directories ¶
Path | Synopsis |
---|---|
Package mock_query is a generated GoMock package.
|
Package mock_query is a generated GoMock package. |