Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrFieldTooLong = fmt.Errorf("%w: field too long", ValidationErr)
View Source
var ErrFieldTooShort = fmt.Errorf("%w: field too short", ValidationErr)
View Source
var ErrMissingField = fmt.Errorf("%w: missing required field", ValidationErr)
View Source
var ErrUnknownField = fmt.Errorf("%w: unkown field", ValidationErr)
View Source
var ValidationErr = errors.New("error validating request")
Functions ¶
This section is empty.
Types ¶
type DefaultFormatter ¶
func (DefaultFormatter) Fields ¶
func (formatter DefaultFormatter) Fields(newFields ...string) DefaultFormatter
func (DefaultFormatter) GetFormattedContent ¶
func (formatter DefaultFormatter) GetFormattedContent(submission Submission) FormattedContent
func (DefaultFormatter) SetFieldName ¶
func (formatter DefaultFormatter) SetFieldName(field, name string) DefaultFormatter
type Destination ¶
a Destination to send submitted forms to
type FieldValidator ¶
type FieldValidator struct {
Fields map[string]FieldValidatorField
}
func (FieldValidator) Accept ¶
func (f FieldValidator) Accept(newFields ...FieldValidatorField) FieldValidator
func (FieldValidator) Validate ¶
func (f FieldValidator) Validate(submission Submission) error
type FieldValidatorField ¶
type FieldValidatorField struct { Name string MinLength int MaxLength int IsOptional bool ValidOptions map[string]bool }
func Field ¶
func Field(name string) FieldValidatorField
func (FieldValidatorField) Max ¶
func (field FieldValidatorField) Max(max int) FieldValidatorField
func (FieldValidatorField) Min ¶
func (field FieldValidatorField) Min(min int) FieldValidatorField
func (FieldValidatorField) MustBe ¶
func (field FieldValidatorField) MustBe(options ...string) FieldValidatorField
func (FieldValidatorField) Optional ¶
func (field FieldValidatorField) Optional() FieldValidatorField
type Form ¶
type Form struct { Name string Destinations []Destination Validators []Validator Formatter Formatter }
represents a form Destinations is a list of destinations to send the submission to Validators is a list of validators that should be run on the submission fields before sending to ensure they are correct Formatter is responsible for formatting the SubmissionFields into a uniform structure that can be sent to destinations
func (Form) DeleteSubmission ¶
func (form Form) DeleteSubmission(submission Submission) (Submission, error)
send a submission to all the Destinations in a form
func (*Form) FormatSubmission ¶
func (form *Form) FormatSubmission(submission Submission) Submission
func (Form) SendSubmission ¶
func (form Form) SendSubmission(submission Submission) (Submission, error)
send a submission to all the Destinations in a form
func (*Form) ValidateSubmission ¶
func (form *Form) ValidateSubmission(submission Submission) error
check if a Submission is valid
type FormattedContent ¶
type FormattedContent struct { Image string Title string Description string Color int Fields []FormattedContentField }
type FormattedContentField ¶
type Formatter ¶
type Formatter interface {
GetFormattedContent(submission Submission) FormattedContent
}
type Sender ¶
type Sender interface { Send(Submission) (messageid string, err error) Edit(string, Submission) (err error) Delete(string) (err error) }
the Sender interface should handle sending, editing, and deleting messages
type Submission ¶
type Submission struct { UUID string FormName string OwnerID string OwnerInfo OwnerInfo CreatedAt time.Time MessageIDS map[string]string Fields SubmissionFields Content FormattedContent Deleted bool DeletedAt time.Time }
submission
func NewSubmission ¶
func NewSubmission(form Form, ownerInfo OwnerInfo) Submission
type SubmissionFields ¶
type SubmissionFields map[string]interface{}
func (SubmissionFields) GetBool ¶
func (fields SubmissionFields) GetBool(key string) bool
func (SubmissionFields) GetString ¶
func (fields SubmissionFields) GetString(key string) string
func (SubmissionFields) Has ¶
func (fields SubmissionFields) Has(key string) bool
type Validator ¶
type Validator interface {
Validate(Submission) error
}
Click to show internal directories.
Click to hide internal directories.