serverx

package
v0.0.575 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: Apache-2.0 Imports: 4 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultNotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	var contentType string
	var body []byte
	switch httputil.NegotiateContentType(r, []string{
		"text/html",
		"text/plain",
		"application/json",
	}, "text/html") {
	case "text/plain":
		contentType = "text/plain"
		body = []byte(`Error 404 - The requested route does not exist. Make sure you are using the right path, domain, and port.`)
	case "application/json":
		contentType = "application/json"
		body = page404JSON
	case "text/html":
		fallthrough
	default:
		contentType = "text/html"
		body = page404HTML
	}

	w.Header().Set("Content-Type", contentType+"; charset=utf-8")
	w.WriteHeader(http.StatusNotFound)
	_, _ = w.Write(body)
})

DefaultNotFoundHandler is a default handler for handling 404 errors.

Functions

func PermanentRedirect added in v0.0.11

func PermanentRedirect(to string) func(rw http.ResponseWriter, r *http.Request, _ httprouter.Params)

PermanentRedirect permanently redirects (302) a path to another one.

Types

This section is empty.

Jump to

Keyboard shortcuts

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