rest

package
v0.0.0-...-6697815 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelDebug logLevel = iota
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
	LevelOff
)

Variables

This section is empty.

Functions

func HandleMetrics

func HandleMetrics(title string, ss []string) http.Handler

func HandleStatic

func HandleStatic(prefix, path string) http.Handler

func HandleWithLogging

func HandleWithLogging(logger *Logger, next http.Handler) http.Handler

func LevelText

func LevelText(level logLevel) string

func WriteResponse

func WriteResponse(w http.ResponseWriter, code int, payload Payload)

Types

type Chain

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

Chain acts as a list of http.Handler middlewares. It's effectively immutable.

func NewChain

func NewChain(mw ...Middleware) *Chain

NewChain creates a new chain, memorizing the given list of middleware handlers. New serves no other function, middlewares are only called upon a call to Then().

func (*Chain) Append

func (c *Chain) Append(mw ...Middleware) *Chain

Append extends a chain, adding the specified constructors as the last ones in the request flow.

func (*Chain) Extend

func (c *Chain) Extend(chain *Chain) *Chain

Extend extends a chain by adding the specified chain as the last one in the request flow.

func (*Chain) Then

func (c *Chain) Then(handler http.Handler) http.Handler

Then chains the middleware and returns the final http.Handler. Then() treats nil as http.DefaultServeMux.

func (*Chain) ThenFunc

func (c *Chain) ThenFunc(handler http.HandlerFunc) http.Handler

ThenFunc works identically to Then, but takes a HandlerFunc instead of a Handler.

type Config

type Config struct {
	StaticHandler http.Handler `json:"-"`
	ErrHandler    http.Handler `json:"-"`
	MetricsOn     bool         `json:"metrics_on"`
	LoggingLevel  int          `json:"logging_level"`
}

type ContentType

type ContentType string
const (
	ContentJSON ContentType = "application/json"
	ContentXML  ContentType = "application/xml"
	ContentHTML ContentType = "text/html"
	ContentText ContentType = "text/plain"
)

type Error

type Error struct {
	Code    int    `json:"code"`
	Status  string `json:"status"`
	Message string `json:"message"`
}

func NewError

func NewError(code int, msg string) *Error

func (*Error) Marshal

func (e *Error) Marshal() ([]byte, error)

type Logger

type Logger struct {
	*log.Logger
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(level logLevel) *Logger

func (*Logger) Debug

func (l *Logger) Debug(s string, a ...interface{})

func (*Logger) Error

func (l *Logger) Error(s string, a ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(s string, a ...interface{})

func (*Logger) Info

func (l *Logger) Info(s string, a ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(s string, a ...interface{})

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is a piece of middleware.

type Payload

type Payload interface {
	Marshal() ([]byte, error)
}

type Raw

type Raw struct {
	Data any
}

func NewRaw

func NewRaw(data any) *Raw

func (*Raw) Marshal

func (raw *Raw) Marshal() ([]byte, error)

type Route

type Route struct {
	Method  string
	Pattern string
	Handler http.Handler
}

type Router

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

func NewRouter

func NewRouter(conf *Config) *Router

func (*Router) Delete

func (rm *Router) Delete(pattern string, handler http.Handler)

func (*Router) Forward

func (rm *Router) Forward(oldpattern string, newpattern string)

func (*Router) Get

func (rm *Router) Get(pattern string, handler http.Handler)

func (*Router) Handle

func (rm *Router) Handle(method string, pattern string, handler http.Handler)

func (*Router) HandleFunc

func (rm *Router) HandleFunc(method, pattern string, handler func(http.ResponseWriter, *http.Request))

func (*Router) Len

func (rm *Router) Len() int

func (*Router) Less

func (rm *Router) Less(i, j int) bool

func (*Router) Post

func (rm *Router) Post(pattern string, handler http.Handler)

func (*Router) Put

func (rm *Router) Put(pattern string, handler http.Handler)

func (*Router) Search

func (rm *Router) Search(x string) int

func (*Router) ServeHTTP

func (rm *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Router) Static

func (rm *Router) Static(pattern string, path string)

func (*Router) Swap

func (rm *Router) Swap(i, j int)

Jump to

Keyboard shortcuts

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