view

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxJSONBody = 1 << 20
View Source
const (
	DefaultPerPage = 10
)

Variables

View Source
var ErrBodyTooLarge = errors.New("coyote/view: request body is too large")

Functions

func Create

func Create(opts Options) http.HandlerFunc

func Decode

func Decode(r *http.Request, target any) error

func DecodeLimit

func DecodeLimit(r *http.Request, target any, maxBytes int64) error

func Delete

func Delete(opts Options) http.HandlerFunc

func Detail

func Detail(opts Options) http.HandlerFunc

func Error

func Error(r *http.Request, message string)

func Flash

func Flash(r *http.Request, kind, message string)

func Info

func Info(r *http.Request, message string)

func JSON

func JSON(w http.ResponseWriter, status int, payload any) error

func JSONError

func JSONError(w http.ResponseWriter, status int, message string) error

func JSONProblems

func JSONProblems(w http.ResponseWriter, status int, problems map[string][]string) error

func List

func List(opts Options) http.HandlerFunc

func Redirect

func Redirect(w http.ResponseWriter, r *http.Request, target string)

func RedirectPermanent

func RedirectPermanent(w http.ResponseWriter, r *http.Request, target string)

func SafeNext

func SafeNext(next, fallback string) string

func Success

func Success(r *http.Request, message string)

func Update

func Update(opts Options) http.HandlerFunc

func WantsJSON

func WantsJSON(r *http.Request) bool

func Warning

func Warning(r *http.Request, message string)

Types

type Data

type Data map[string]any

func (Data) Merge

func (d Data) Merge(other Data) Data

func (Data) Set

func (d Data) Set(key string, value any) Data

func (Data) SetDefault

func (d Data) SetDefault(key string, value any) Data

type Options

type Options struct {
	Store     model.Store
	Schema    *model.Schema
	Template  string
	Renderer  Renderer
	PerPage   int
	Paginator Paginator
	Order     string
	Fields    []string
	Exclude   []string
	Filter    func(*http.Request, model.Query) model.Query
	Allow     func(*http.Request) bool
	Data      func(*http.Request, Data) Data
	Redirect  string
	IDParam   string
}

type Page

type Page struct {
	Enabled bool
	Number  int
	PerPage int
	Total   int64
	Pages   int
	Offset  int
	Limit   int
	HasPrev bool
	HasNext bool
	Prev    int
	Next    int
	First   int
	Last    int
	Numbers []int
}

func Paginate

func Paginate(paginator Paginator, total int64, number, perPage int) Page

func (Page) Empty

func (p Page) Empty() bool

func (Page) Single

func (p Page) Single() bool

type Pages

type Pages struct {
	Window int
}

func (Pages) Paginate

func (d Pages) Paginate(total int64, number, perPage int) Page

type Paginator

type Paginator interface {
	Paginate(total int64, number, perPage int) Page
}

type Renderer

type Renderer interface {
	RenderStatus(w http.ResponseWriter, r *http.Request, status int, page string, data Data)
}

Jump to

Keyboard shortcuts

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