rest

package
v0.0.0-...-02bf512 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package rest provides functions for simple REST handling

SPDX-License-Identifier: Apache-2.0

Package rest provides functions for simple REST handling

SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	NotFoundMsg         = "Not Found"
	MethodNotAllowedMsg = "Method Not Allowed"
)
View Source
const (
	UUIDGroup = "([0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12})"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request, urlParts []string)
}

Handler is a REST handler The only difference compared to http.Handler is en extra argument of regex matches for url parts, so that the handler doesn't to re-evaluate the same regex a second time to get those values.

type HandlerFunc

type HandlerFunc func(w http.ResponseWriter, r *http.Request, urlParts []string)

HandlerFunc is an adapter func for Handler

func (HandlerFunc) ServeHTTP

func (hf HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, urlParts []string)

ServeHTTP is HandlerFunc adapter method

type ServeMux

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

A ServeMux handles REST requests by performing pattern matching that considers the method and URL, rather than just the URL alone like the http.ServeMux implementation. The zero value is ready to use.

func (*ServeMux) Handle

func (rsm *ServeMux) Handle(method, pattern string, handler Handler) error

Handle maps the given method and regex string to the given handler. The regex allows capturing path parts that are variable, like a UUID. The Handle can be called anytime, even while HTTP requests are being served.

func (*ServeMux) MustHandle

func (rsm *ServeMux) MustHandle(method, pattern string, handler Handler)

MustHandle is a must version of Handle

func (ServeMux) ServeHTTP

func (rsm ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is http.Handler interface method

Jump to

Keyboard shortcuts

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