web

package
v0.0.0-...-9790b92 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

https://blog.questionable.services/article/http-handler-error-handling-revisited/

Index

Constants

View Source
const ContextKeyIsAuthenticated = contextKey("isAuthenticated")

Variables

This section is empty.

Functions

func IsAuthenticated

func IsAuthenticated(e *env.Env, r *http.Request) bool

IsAuthenticated checks the current request for an authenticated user.

func Params

func Params(r *http.Request) map[string]string

Params returns the web call parameters from the request.

func Render

func Render(e *env.Env, w http.ResponseWriter, r *http.Request, tmpl string, dt interface{}, statusCode int) error

Render renders a HTML page to the client.

Types

type Error

type Error interface {
	error
	Status() int
}

Error represents a handler error. It provides methods for a HTTP status code and embeds the built-in error interface.

type Handler

type Handler struct {
	E *env.Env
	H func(E *env.Env, w http.ResponseWriter, r *http.Request) error
}

Handler takes a configured Env.

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP allows the Handler to satisfy the http.Handler interface.

type NeuteredFileSystem

type NeuteredFileSystem struct {
	Fs http.FileSystem
}

NeuteredFileSystem is a custom file system to disable directory listings.

func (NeuteredFileSystem) Open

func (nfs NeuteredFileSystem) Open(path string) (http.File, error)

Open opens the files from the custom file system.

type StatusError

type StatusError struct {
	Err  error
	Code int
}

StatusError represents an error with an associated HTTP status code.

func (StatusError) Error

func (se StatusError) Error() string

Allows StatusError to satisfy the error interface.

func (StatusError) Status

func (se StatusError) Status() int

Returns our HTTP status code.

Jump to

Keyboard shortcuts

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