rest

package
v0.0.0-...-a507d04 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

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"

	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

func AcceptGzip

func AcceptGzip(r *http.Request) goio.Reader

AcceptGzip checks if the request Accept-Encoding header is gzip. If so, it returns a new io.Reader which decompresses the body io.Reader using gzip. Otherwise, it returns the body io.Reader as is.

func NegotiateCSVContent

func NegotiateCSVContent(r *http.Request) iter.Iter[[]string]

NegotiateCSVContent returns an Iter[[]string] if the Content-Type header is text/csv, otherwise it returns nil

func NegotiateJSONContent

func NegotiateJSONContent(r *http.Request) iter.Iter[json.Value]

NegotiateJSONContent returns an Iter[json.Value] if the Content-Type header is application/json, otherwise it returns nil

Types

type Handler

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

Handler is a REST handler The only difference compared to http.Handler is an extra argument of regex matches for url parts, so that the handler doesn't have 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) Serve

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

Serve 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 (sm *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. This method can be called any time, even while HTTP requests are being served.

func (*ServeMux) MustHandle

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

MustHandle is a must version of Handle

func (ServeMux) ServeHTTP

func (sm 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