router

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorResponder

type ErrorResponder interface {
	RespondError(w http.ResponseWriter, r *http.Request, re *Router) bool
}

ErrorResponder responds with error

type HTTPStatusError

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

HTTPStatusError http statuscode errors

func HTTPError

func HTTPError(statuscode int, err error) *HTTPStatusError

HTTPError handle HTTP error

func HTTPErrorWithBody

func HTTPErrorWithBody(body interface{}, statuscode int, err error) *HTTPStatusError

HTTPErrorWithBody handle HTTP error with body

func HTTPErrorWithReport

func HTTPErrorWithReport(statuscode int, err error) *HTTPStatusError

HTTPErrorWithReport handle HTTP error returning status report

func (*HTTPStatusError) Error

func (e *HTTPStatusError) Error() string

Error returns HTTP error

func (*HTTPStatusError) RespondError

func (e *HTTPStatusError) RespondError(w http.ResponseWriter, r *http.Request, re *Router) bool

RespondError HTTP error response

type HandlerFunc

type HandlerFunc func(w http.ResponseWriter, r *http.Request) error

HandlerFunc custom handler function that passes errors

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Page

type Page struct {
	App       interface{}
	CSRFField template.HTML
	Content   interface{}
}

Page web page

type Response

type Response struct {
	Title   string
	Vars    map[string]string
	Query   url.Values
	Session map[interface{}]interface{}
	Body    interface{}
	Status  Status
}

Response HTTP Response

type Router

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

Router Configuration

func NewRouter

func NewRouter(tplopts *tpl.Options, page interface{}, logger *logger.Logger, fsys fs.FS) *Router

NewRouter instance of new router

func (*Router) FileHandler

func (re *Router) FileHandler(ph string) HandlerFunc

FileHandler handles loading file assets

func (*Router) HandlePage

func (re *Router) HandlePage(title string, body interface{}) http.HandlerFunc

HandlePage handles page requests with body

func (*Router) HandlePprof

func (re *Router) HandlePprof() http.HandlerFunc

HandlePprof pprof index

func (*Router) HandlePprofProfile

func (re *Router) HandlePprofProfile() http.HandlerFunc

HandlePprofProfile pprof profile

func (*Router) RenderTemplate

func (re *Router) RenderTemplate(data interface{}) http.HandlerFunc

RenderTemplate renders html templates

func (*Router) Respond

func (re *Router) Respond(data interface{}, status int) http.HandlerFunc

Respond responds with data json

func (*Router) Response

func (re *Router) Response(resp *Response, statuscode int) HandlerFunc

Response handles http respondes

func (*Router) Router

func (re *Router) Router() *mux.Router

Router returns router

func (*Router) WithError

func (re *Router) WithError(h HandlerFunc) http.HandlerFunc

WithError error handler

type Status

type Status struct {
	Status     string
	StatusCode int
}

Status HTTP Status Code

Jump to

Keyboard shortcuts

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