rest

package
v0.0.0-...-c864ae1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: BSD-2-Clause, BSD-3-Clause, MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const CacheControlHeaderKey = "Cache-Control"
View Source
const ContentTypeHeaderKey = "Content-Type"
View Source
const CsvMimeType = "text/csv"
View Source
const DefaultCacheMaxAgeInSeconds = 10
View Source
const DefaultResponseContentType = JsonMimeType
View Source
const JsonMimeType = "application/json"
View Source
const TextMimeType = "text/plain"
View Source
const TomlMimeType = "application/toml"
View Source
const UrlPathSeparator = "/"

Variables

This section is empty.

Functions

func FormattedTimestamp

func FormattedTimestamp() string

func SendTextOnResponseBody

func SendTextOnResponseBody(text string, w http.ResponseWriter)

Below useful for quick debugging.

Types

type HandlerFunc

type HandlerFunc http.HandlerFunc

type HandlerFunctionMap

type HandlerFunctionMap map[*regexp.Regexp]HandlerFunc

func (HandlerFunctionMap) AddHandler

func (m HandlerFunctionMap) AddHandler(addressPattern string, handler HandlerFunc)

type MessageResponse

type MessageResponse struct {
	Type    string
	Message string
	Time    string
}

type Mux

type Mux interface {
	Start(portAddress string)
	Shutdown()

	SetLogger(handler logging.Logger)
	AddHandler(address string, handler HandlerFunc)

	SetCacheMaxAge(maxAge uint64)
	CacheMaxAge() uint64
}

type MuxImpl

type MuxImpl struct {
	http.ServeMux

	HandlerMap HandlerFunctionMap
	// contains filtered or unexported fields
}

func (*MuxImpl) AddHandler

func (mi *MuxImpl) AddHandler(address string, handler HandlerFunc)

func (*MuxImpl) BadRequestError

func (mi *MuxImpl) BadRequestError(w http.ResponseWriter, r *http.Request)

func (*MuxImpl) CacheMaxAge

func (mi *MuxImpl) CacheMaxAge() uint64

func (*MuxImpl) Initialise

func (mi *MuxImpl) Initialise() *MuxImpl

func (*MuxImpl) InternalServerError

func (mi *MuxImpl) InternalServerError(w http.ResponseWriter, r *http.Request, errorDetail error)

func (*MuxImpl) Logger

func (mi *MuxImpl) Logger() logging.Logger

func (*MuxImpl) MethodNotAllowedError

func (mi *MuxImpl) MethodNotAllowedError(w http.ResponseWriter, r *http.Request)

func (*MuxImpl) NotFoundError

func (mi *MuxImpl) NotFoundError(w http.ResponseWriter, r *http.Request)

func (*MuxImpl) RespondWithError

func (mi *MuxImpl) RespondWithError(responseCode int, responseMsg string, w http.ResponseWriter, r *http.Request)

func (*MuxImpl) ServeHTTP

func (mi *MuxImpl) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*MuxImpl) Server

func (mi *MuxImpl) Server() *http.Server

func (*MuxImpl) ServiceUnavailableError

func (mi *MuxImpl) ServiceUnavailableError(w http.ResponseWriter, r *http.Request, errorDetail error)

func (*MuxImpl) SetCacheMaxAge

func (mi *MuxImpl) SetCacheMaxAge(maxAgeInSeconds uint64)

func (*MuxImpl) SetLogger

func (mi *MuxImpl) SetLogger(logger logging.Logger)

func (*MuxImpl) Shutdown

func (mi *MuxImpl) Shutdown()

func (*MuxImpl) Start

func (mi *MuxImpl) Start(address string)

func (*MuxImpl) UnsupportedMediaTypeError

func (mi *MuxImpl) UnsupportedMediaTypeError(w http.ResponseWriter, r *http.Request)

func (*MuxImpl) WithCacheMaxAge

func (mi *MuxImpl) WithCacheMaxAge(maxAgeInSeconds uint64) *MuxImpl

func (*MuxImpl) WithType

func (mi *MuxImpl) WithType(muxType string) *MuxImpl

type Response

type Response struct {
	ResponseCode int
	ContentType  string
	CacheControl string
	Content      string
	Writer       http.ResponseWriter
	// contains filtered or unexported fields
}

func (*Response) Initialise

func (r *Response) Initialise() *Response

func (*Response) WithCacheControlMaxAge

func (r *Response) WithCacheControlMaxAge(cacheMaxAgeInSeconds uint64) *Response

func (*Response) WithCacheControlPublic

func (r *Response) WithCacheControlPublic() *Response

func (*Response) WithContentType

func (r *Response) WithContentType(contentType string) *Response

func (*Response) WithCsvContent

func (r *Response) WithCsvContent(content interface{}) *Response

func (*Response) WithJsonContent

func (r *Response) WithJsonContent(content interface{}) *Response

func (*Response) WithResponseCode

func (r *Response) WithResponseCode(responseCode int) *Response

func (*Response) WithTextContent

func (r *Response) WithTextContent(content string) *Response

func (*Response) WithTomlContent

func (r *Response) WithTomlContent(content interface{}) *Response

func (*Response) WithWriter

func (r *Response) WithWriter(writer http.ResponseWriter) *Response

func (*Response) Write

func (r *Response) Write() error

Jump to

Keyboard shortcuts

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