Documentation ¶
Index ¶
- Variables
- type Data
- type Form
- type FormWithCaptcha
- type Mongo
- func (m *Mongo) Count(ctx context.Context) int64
- func (m *Mongo) Create(ctx context.Context, f Form) (string, error)
- func (m *Mongo) Delete(ctx context.Context, id string) error
- func (m *Mongo) Read(ctx context.Context, id string) (Form, error)
- func (m *Mongo) ReadAll(ctx context.Context, batch, page int64) ([]Form, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrMongoNotFound is returned when a given ID cannot be // found in the MongoDB collection. ErrMongoNotFound = errors.New("document not found") // ErrMongoNilColl is returned when a Nil collection is // given to NewMongo(). ErrMongoNilColl = errors.New("collection cannot be nil") // ErrMongoFailCreate is returned when MongoDB fails to // create a new mailbox entry. ErrMongoFailCreate = errors.New("could not submit form, please try again later") // ErrMongoFailDelete is returned when MongoDB fails to // delete a mailbox entry. ErrMongoFailDelete = errors.New("could not delete form, please try again later") // ErrMongoInvalidID is returned when referencing an invalid // Mongo document ID. ErrMongoInvalidID = errors.New("invalid resource id") // ErrMongoInternal is returned when an internal database // error occurs. ErrMongoInternal = errors.New("internal server error") )
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data interface { // Count returns the number of entries in the mailbo. Count(ctx.Context) int64 // ReadAll fetches batches of entries of arbitrary size. // See the implementation in mongo.go. ReadAll(ctx.Context, int64, int64) ([]Form, error) // Read fetches a single entry by referencing it's ID. Read(ctx.Context, string) (Form, error) // Create a new mailbox entry. Create(ctx.Context, Form) (string, error) // Delete a mailbox entry by referencing its ID. Delete(ctx.Context, string) error }
Data defines the Mailbox database interface.
type Form ¶
type Form struct { ID string `json:"id" bson:"_id,omitempty"` From string `json:"from" bson:"from" binding:"required"` Subject string `json:"subject" bson:"subject" binding:"required"` Message string `json:"message" bson:"message" binding:"required"` }
Form defines a single mailbox entry.
type FormWithCaptcha ¶
FormWithCaptcha encapsulates a Form with a captcha token and RemoteIP attribute. It is used to validate Turnstile captchas.
type Mongo ¶
type Mongo struct {
// contains filtered or unexported fields
}
Mongo implements the Data interface with a MongoDB backend.
Click to show internal directories.
Click to hide internal directories.