shared

package
v0.0.0-...-0ab8b5a Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const FromTimeFormat = "2006-01-02T15-04-05"

Variables

View Source
var (
	ErrNotFound         = errors.New("page not found")
	ErrMethodNotAllowed = errors.New("method not allowed")
)

Functions

func ErrorHandler

func ErrorHandler(exec templates.Executor, w http.ResponseWriter, r *http.Request, err error)

func PageAndOffset

func PageAndOffset(r *http.Request, pageSize int64) (int64, int64, error)

func PageCount

func PageCount(total, size int64) int64

Types

type ErrorInput

type ErrorInput struct {
	middleware.Input
	StatusCode int
	Message    string
	Error      error
	RequestID  xid.ID
}

func (ErrorInput) TemplateBundle

func (ErrorInput) TemplateBundle() string

type FromPagination

type FromPagination[T constraints.Unsigned] struct {
	Key T
	Nr  int
	// contains filtered or unexported fields
}

func NewFromPagination

func NewFromPagination[T constraints.Unsigned](key T, prev, next []T, uri *url.URL) *FromPagination[T]

func (*FromPagination[T]) BaseURL

func (p *FromPagination[T]) BaseURL() template.URL

func (*FromPagination[T]) First

func (p *FromPagination[T]) First() *FromPagination[T]

First returns the first page, this uses time.Now() as the Key and 1 as the page number.

func (*FromPagination[T]) Last

func (p *FromPagination[T]) Last() *FromPagination[T]

Last returns the last page, will return nil if WithLast wasn't called beforehand on a parent

func (*FromPagination[T]) Next

func (p *FromPagination[T]) Next(offset int) *FromPagination[T]

Next returns the next page as indicated by the offset from current

func (*FromPagination[T]) Prev

func (p *FromPagination[T]) Prev(offset int) *FromPagination[T]

Prev returns the previous page as indicated by the offset from current

func (*FromPagination[T]) URL

func (p *FromPagination[T]) URL() template.URL

func (*FromPagination[T]) WithLast

func (p *FromPagination[T]) WithLast(key T, nr int) *FromPagination[T]

WithLast returns a page with the last page info set to key and nr

func (*FromPagination[T]) WithPage

func (p *FromPagination[T]) WithPage(nr int) *FromPagination[T]

WithPage returns a page with the page number set to nr

type NewsCache

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

func NewNewsCache

func NewNewsCache() *NewsCache

func (*NewsCache) Empty

func (nc *NewsCache) Empty(post radio.NewsPost)

Empty clears the cache of the post given, this clears the Body and Header cache

func (*NewsCache) EmptyBefore

func (nc *NewsCache) EmptyBefore(t time.Time)

EmptyBefore removes any entries from the cache that had been generated before the time given

func (*NewsCache) RenderBody

func (nc *NewsCache) RenderBody(post radio.NewsPost) (NewsMarkdown, error)

func (*NewsCache) RenderBypass

func (nc *NewsCache) RenderBypass(source string) (NewsMarkdown, error)

RenderBypass renders string as markdown and skips the cache mechanism, source should come from a trusted input

func (*NewsCache) RenderBypassCache

func (nc *NewsCache) RenderBypassCache(post radio.NewsPost) (header, body NewsMarkdown, err error)

RenderBypassCache renders a news post header and body as markdown and skips the cache mechanism

func (*NewsCache) RenderComment

func (nc *NewsCache) RenderComment(comment radio.NewsComment) (NewsMarkdown, error)

func (*NewsCache) RenderError

func (nc *NewsCache) RenderError(err error) NewsMarkdown

func (*NewsCache) RenderHeader

func (nc *NewsCache) RenderHeader(post radio.NewsPost) (NewsMarkdown, error)

type NewsMarkdown

type NewsMarkdown struct {
	GeneratedAt   time.Time
	HasHiddenHTML bool
	Source        string
	Output        template.HTML
}

type Pagination

type Pagination struct {
	Nr    int64
	Total int64
	// contains filtered or unexported fields
}

func NewPagination

func NewPagination(currentPage, totalPages int64, uri *url.URL) *Pagination

func (*Pagination) BaseURL

func (p *Pagination) BaseURL() template.URL

func (*Pagination) First

func (p *Pagination) First() *Pagination

func (*Pagination) Last

func (p *Pagination) Last() *Pagination

func (*Pagination) Next

func (p *Pagination) Next(offset int64) *Pagination

func (*Pagination) Prev

func (p *Pagination) Prev(offset int64) *Pagination

func (*Pagination) URL

func (p *Pagination) URL() template.URL

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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