web

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPageLen error = errors.New("pageLen cannot be below 1")
View Source
var ErrTokenMissingOrInvalid = errors.New("token missing or invalid")
View Source
var Exiter func(code int) = os.Exit

Exiter is the local Exit func

View Source
var StaticEmbeddedFS embed.FS
View Source
var TemplatesEmbeddedFS embed.FS

Functions

This section is empty.

Types

type ErrInvalidPageNo

type ErrInvalidPageNo struct {
	PageNo     int
	TotalPages int
}

func (ErrInvalidPageNo) Error

func (e ErrInvalidPageNo) Error() string

type LinkOrUnlinkForm

type LinkOrUnlinkForm struct {
	Typer       string   `schema:"type"`
	ID          string   `schema:"id"`     // the invoice id or bank-transaction reference
	Action      string   `schema:"action"` // "link" or "unlink"
	DonationIDs []string `schema:"donation-ids"`
}

LinkOrUnlinkForm is a form for linking or unlinking donations in Salesforce to a Xero Invoice or BankTransaction.

func CheckLinkOrUnlinkForm

func CheckLinkOrUnlinkForm(postData map[string][]string, routeVars map[string]string) (*LinkOrUnlinkForm, error)

CheckLinkOrUnlinkForm coleects the postData and routeVars into a map for schema decoding.

func (*LinkOrUnlinkForm) AsSalesforceIDRefs

func (loul *LinkOrUnlinkForm) AsSalesforceIDRefs(dfk string) []salesforce.IDRef

AsSalesforceIDRefs expands a form into a slice of salesforce.IDRef suitable for providing to the salesforce BatchUpdateOpportunityRefs client method. An unlinking always sets the DFK ref to an empty string.

func (*LinkOrUnlinkForm) Validate

func (f *LinkOrUnlinkForm) Validate(v *Validator)

Validate valides the link or unlink form.

type Pagination

type Pagination struct {
	PageNo   int
	Pages    int
	Next     int // 0 means no next page
	Previous int // 0 means no previous page
	// contains filtered or unexported fields
}

Pagination is a pagination helper type for use on listing pages.

func NewPagination

func NewPagination(pageLen, totalRecords, currentPage int, query url.Values) (*Pagination, error)

NewPagination calculates the pagination setting for the provided pageLen (number of items to show per page), the current page number, the total records in the current set and the present url values. The url values are used for determining the url (if any) for the "Next" and "Previous" pages.

func (*Pagination) NextURL

func (p *Pagination) NextURL() string

NextURL returns the URL for the next page. Returns empty string if no next page.

func (*Pagination) PreviousURL

func (p *Pagination) PreviousURL() string

PreviousURL returns the URL for the previous page. Returns empty string if no prev page.

type SearchDonationsForm

type SearchDonationsForm struct {
	LinkageStatus   string    `schema:"status" url:"status"`
	DateFrom        time.Time `schema:"date-from" url:"date-from" layout:"2006-01-02"`
	DateTo          time.Time `schema:"date-to" url:"date-to" layout:"2006-01-02"`
	PayoutReference string    `schema:"payout-reference" url:"payout-reference"`
	SearchString    string    `schema:"search" url:"search"`
	Page            int       `schema:"page" url:"page"`
	Refresh         bool      `schema:"refresh" url:"-"`
	Reset           bool      `schema:"reset" url:"-"`
}

SearchDonationsForm represents the URL query parameter filters for donations.

func NewSearchDonationsForm

func NewSearchDonationsForm(startDate, endDate *time.Time) *SearchDonationsForm

NewSearchDonationsForm creates a SearchDonationsForm with defaults.

func (*SearchDonationsForm) AsURLParams

func (s *SearchDonationsForm) AsURLParams() (string, error)

AsURLParams encodes a SearchForm as parameters for after the "?" in a url

func (*SearchDonationsForm) DecodeURLParams added in v0.0.13

func (f *SearchDonationsForm) DecodeURLParams(urlQuery map[string][]string) error

DecodeURLParams decodes a url query into the form.

func (*SearchDonationsForm) Offset

func (f *SearchDonationsForm) Offset(pageLen int) int

Offset calculates the database offset for (1-based) pagination.

func (*SearchDonationsForm) Validate

func (f *SearchDonationsForm) Validate(v *Validator)

Validate checks SearchDonationsForm fields and populates Validator with any errors. Note that the `Check` is like an assertion of truth, if that fails, the provided message is recorded against the field.

type SearchForm

type SearchForm struct {
	ReconciliationStatus string    `schema:"status" url:"status"`
	DateFrom             time.Time `schema:"date-from" url:"date-from" layout:"2006-01-02"`
	DateTo               time.Time `schema:"date-to" url:"date-to" layout:"2006-01-02"`
	SearchString         string    `schema:"search" url:"search"`
	Page                 int       `schema:"page" url:"page"`
	Refresh              bool      `schema:"refresh" url:"-"`
	Reset                bool      `schema:"reset" url:"-"`
}

SearchForm represents the URL query parameter filters (invoices, bank transactions, and so on.)

func NewSearchForm

func NewSearchForm(startDate, endDate *time.Time) *SearchForm

NewSearchForm creates a SearchForm with defaults.

func (*SearchForm) AsURLParams

func (s *SearchForm) AsURLParams() (string, error)

AsURLParams encodes a SearchForm as parameters for after the "?" in a url

func (*SearchForm) DecodeURLParams added in v0.0.13

func (f *SearchForm) DecodeURLParams(urlQuery map[string][]string) error

DecodeURLParams decodes a url query into a form.

func (*SearchForm) Offset

func (f *SearchForm) Offset(pageLen int) int

Offset calculates the database offset for (1-based) pagination.

func (*SearchForm) Validate

func (f *SearchForm) Validate(v *Validator)

Validate checks SearchForm fields and populates Validator with any errors. Note tha the `Check` is like an assertion of truth, if that fails, the provided message is recorded against the field.

type Validator

type Validator struct {
	Errors map[string]string
}

Validator holds a map of validation errors, keyed by the form field name.

func NewValidator

func NewValidator() *Validator

NewValidator creates a new, initialized Validator.

func (*Validator) AddError

func (v *Validator) AddError(key, message string)

AddError adds an error message to the map for a given field if one doesn't already exist for that field.

func (*Validator) Check

func (v *Validator) Check(ok bool, key, message string)

Check is a helper for conditional validation. If `ok` is false, it calls AddError with the provided key and message.

func (*Validator) FieldError

func (v *Validator) FieldError(field string) bool

FieldError is a helper to check if the specified field has triggered an error.

func (*Validator) Valid

func (v *Validator) Valid() bool

Valid returns true if the Errors map is empty.

type WebApp

type WebApp struct {
	// contains filtered or unexported fields
}

WebApp is the configuration object for the web server.

func New

func New(
	config *config.Config,
	reconciler reconcilerer,
	logger *slog.Logger,
	staticFS fs.FS,
	templateFS fs.FS,
	xeroClientFunc xeroClientMaker,
	sfClientFunc sfClientMaker,
) (*WebApp, error)

New initialises a WebApp. An error type is returned for future use.

func (*WebApp) ErrorChecker added in v0.0.13

func (web *WebApp) ErrorChecker(h appHandler) http.Handler

ErrorChecker wraps appHandler (handlers that return an error). This allows error reporting to be centralised, and the appHandlers to be simplified by avoiding error handling boilerplate.

func (*WebApp) RestartRoutes

func (web *WebApp) RestartRoutes()

RestartRoutes reruns the route setup. This should only be used in development mode to re-compile templates. Panics are caught through recover but the routes are not restarted.

func (*WebApp) SetInDevelopment

func (web *WebApp) SetInDevelopment()

SetInDevelopment is a development-mode switch for setting the web app in development mode. This has no effect if called after the server has started.

func (*WebApp) StartServer

func (web *WebApp) StartServer() error

StartServer starts a WebApp.

Jump to

Keyboard shortcuts

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