api

package
v0.3.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNoValidObject           = "no valid form object found"
	ErrHCaptchaValidateFailed  = "hCaptcha validation failed"
	ErrReCaptchaVaildateFailed = "reCaptcha validation failed"
	ErrTurnstileVaildateFailed = "Turnstile validation failed"
)

List of common errors

Variables

View Source
var (
	ErrReadHTTPResponseBody = "reading HTTP response body: %s"
	ErrJSONUnmarshal        = "HTTP response JSON unmarshalling: %s"
)

Functions

func GetMailClient added in v0.2.4

func GetMailClient(f *form.Form) (*mail.Client, error)

GetMailClient returns a new mail dailer object based on the form configuration

func SendFormConfirmation added in v0.2.2

func SendFormConfirmation(f *form.Form, r string) error

SendFormConfirmation sends out a confirmation mail if requested in the form

Types

type CaptchaResponse

type CaptchaResponse struct {
	Success            bool   `json:"success"`
	ChallengeTimestamp string `json:"challenge_ts"`
	Hostname           string `json:"hostname"`
}

CaptchaResponse reflect the API response from various 3rd party captcha services

type HcaptchaResponse

type HcaptchaResponse CaptchaResponse

HcaptchaResponse is the CaptchaResponse for hCaptcha

type PingResponse

type PingResponse struct {
	StatusCode int
	Status     string
	Data       interface{}
}

PingResponse reflects the JSON structure for a ping response

type ReCaptchaResponse

type ReCaptchaResponse CaptchaResponse

ReCaptchaResponse is the CaptchaResponse for Google ReCaptcha

type Route

type Route struct {
	Cache  *ttlcache.Cache
	Config *config.Config
}

Route represents an API route object

func (*Route) GetForm

func (r *Route) GetForm(i string) (form.Form, error)

GetForm gets a form.Form object either from the in-memory cache or if not cached yet, from the file system

func (*Route) GetToken

func (r *Route) GetToken(c echo.Context) error

GetToken handles the HTTP token requests and return a TokenResponse on success or an error on failure

func (*Route) Ping

func (r *Route) Ping(c echo.Context) error

Ping is a test route for the API

func (*Route) SendForm

func (r *Route) SendForm(c echo.Context) error

SendForm handles the HTTP form sending API request

func (*Route) SendFormBindForm

func (r *Route) SendFormBindForm(next echo.HandlerFunc) echo.HandlerFunc

SendFormBindForm is a middleware that validates the provided form data and binds it to a SendFormRequest object

func (*Route) SendFormCheckToken

func (r *Route) SendFormCheckToken(next echo.HandlerFunc) echo.HandlerFunc

SendFormCheckToken is a middleware that checks the form security token

func (*Route) SendFormHcaptcha

func (r *Route) SendFormHcaptcha(next echo.HandlerFunc) echo.HandlerFunc

SendFormHcaptcha is a middleware that checks the form data against hCaptcha

func (*Route) SendFormHoneypot

func (r *Route) SendFormHoneypot(next echo.HandlerFunc) echo.HandlerFunc

SendFormHoneypot is a middleware that checks that a configured honeypot field is not filled with any data

func (*Route) SendFormRecaptcha

func (r *Route) SendFormRecaptcha(next echo.HandlerFunc) echo.HandlerFunc

SendFormRecaptcha is a middleware that checks the form data against Google ReCaptcha

func (*Route) SendFormReqFields

func (r *Route) SendFormReqFields(next echo.HandlerFunc) echo.HandlerFunc

SendFormReqFields is a middleware that validates that all required fields are set in the SendFormRequest object

func (*Route) SendFormTurnstile added in v0.3.0

func (r *Route) SendFormTurnstile(next echo.HandlerFunc) echo.HandlerFunc

SendFormTurnstile is a middleware that checks the form data against Cloudflare Turnstile

type SendFormRequest

type SendFormRequest struct {
	FormID    string `param:"fid"`
	FormObj   *form.Form
	Token     string `param:"token"`
	TokenResp *TokenResponse
}

SendFormRequest reflects the structure of the send form request data

type SentSuccessful added in v0.2.2

type SentSuccessful struct {
	FormID           string `json:"form_id"`
	SendTime         int64  `json:"send_time"`
	ConfirmationSent bool   `json:"confirmation_sent"`
	ConfirmationRcpt string `json:"confirmation_rcpt"`
}

SentSuccessful represents confirmation JSON structure for a successfully sent message

type TokenRequest

type TokenRequest struct {
	FormID string `query:"formid" form:"formid"`
}

TokenRequest reflects the incoming gettoken request data that for the parameter binding

type TokenResponse

type TokenResponse struct {
	Token      string `json:"token"`
	FormID     string `json:"form_id"`
	CreateTime int64  `json:"create_time,omitempty"`
	ExpireTime int64  `json:"expire_time,omitempty"`
	URL        string `json:"url"`
	EncType    string `json:"enc_type"`
	Method     string `json:"method"`
}

TokenResponse reflects the JSON response struct for token request

type TurnstileResponse added in v0.3.0

type TurnstileResponse CaptchaResponse

TurnstileResponse is the CaptchaResponse for Cloudflare Turnstile

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL