srv

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderContentType     = "Content-Type"
	HeaderAccept          = "Accept"
	HeaderContentEncoding = "Content-Encoding"
)
View Source
const (
	ContentTypeJSONUTF8 = "application/json; charset=utf-8"
)

Variables

This section is empty.

Functions

func Cors

func Cors() func(http.Handler) http.Handler

func GZIP

func GZIP() func(http.Handler) http.Handler

func Logging

func Logging(dumpRequest bool) func(http.Handler) http.Handler

func Recovery

func Recovery() func(http.Handler) http.Handler

func Var

func Var(r *http.Request, key string) string

Var extract a variable formerly registered by {} from the request

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any)

Types

type Filter

type Filter struct {
	Name       string
	Comparator FilterComparator
	Value      string
}

Filter defines a general filter

type FilterComparator

type FilterComparator string

FilterComparator types a comparator

const (
	FilterComparatorEqual   FilterComparator = "eq"
	FilterComparatorLess    FilterComparator = "ls"
	FilterComparatorGreater FilterComparator = "gt"
	FilterComparatorLike    FilterComparator = "like"
)

type IgnoreTrailingSlashes

type IgnoreTrailingSlashes struct{}

type Meta

type Meta struct {
	Limit   int
	Skip    int
	Filters []Filter
	Sorts   SortComponents
}

Meta holds various filter and query parameters passed with a http request

func ParseMeta

func ParseMeta(r *http.Request) (Meta, error)

ParseMeta parses meta-data from a http request

func (*Meta) ChangeFilterValueInt

func (m *Meta) ChangeFilterValueInt(name string, v int)

func (Meta) FilterValue

func (m Meta) FilterValue(name string) interface{}

func (Meta) FilterValueBool

func (m Meta) FilterValueBool(name string) bool

func (Meta) FilterValueFloat

func (m Meta) FilterValueFloat(name string) float64

func (Meta) FilterValueInt

func (m Meta) FilterValueInt(name string) int

func (Meta) FilterValueString

func (m Meta) FilterValueString(name string) string

func (Meta) Query

func (m Meta) Query() string

func (Meta) SortOrder

func (m Meta) SortOrder(name string) SortOrder

type PrefixRouter

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

PrefixRouter is a router, which routes prefixed routes

func (*PrefixRouter) DELETE

func (r *PrefixRouter) DELETE(pattern string, handle http.HandlerFunc, options ...interface{})

DELETE registers a DELETE handler

func (*PrefixRouter) GET

func (r *PrefixRouter) GET(pattern string, handle http.HandlerFunc, options ...interface{})

GET registers a GET handler

func (*PrefixRouter) HEAD

func (r *PrefixRouter) HEAD(pattern string, handle http.HandlerFunc, options ...interface{})

HEAD registers a HEAD handler

func (*PrefixRouter) Handler

func (r *PrefixRouter) Handler(mwares ...mux.MiddlewareFunc) http.Handler

func (*PrefixRouter) POST

func (r *PrefixRouter) POST(pattern string, handle http.HandlerFunc, options ...interface{})

POST registers a POST handler

func (*PrefixRouter) PUT

func (r *PrefixRouter) PUT(pattern string, handle http.HandlerFunc, options ...interface{})

PUT registers a PUT handler

func (*PrefixRouter) Prefix

func (r *PrefixRouter) Prefix() string

func (*PrefixRouter) PrefixGET

func (r *PrefixRouter) PrefixGET(prefix string, handle http.HandlerFunc, options ...interface{})

PrefixGET registers a GET handler, which matches all routes with the given prefix

func (*PrefixRouter) Resolve

func (r *PrefixRouter) Resolve(pattern string) string

func (*PrefixRouter) WithPrefix

func (r *PrefixRouter) WithPrefix(prefix string) *PrefixRouter

type Router

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

Router encapsulates a http router

func NewRouter

func NewRouter() *Router

NewRouter creates a new router

func (*Router) DELETE

func (r *Router) DELETE(pattern string, handle http.HandlerFunc, options ...interface{})

func (*Router) GET

func (r *Router) GET(pattern string, handle http.HandlerFunc, options ...interface{})

GET registers a GET handler

func (*Router) HEAD

func (r *Router) HEAD(pattern string, handle http.HandlerFunc, options ...interface{})

func (*Router) Handler

func (r *Router) Handler(mwares ...mux.MiddlewareFunc) http.Handler

Handler returns the http handler of the router

func (*Router) POST

func (r *Router) POST(pattern string, handle http.HandlerFunc, options ...interface{})

POST registers a POST handler

func (*Router) PUT

func (r *Router) PUT(pattern string, handle http.HandlerFunc, options ...interface{})

func (*Router) PrefixDELETE

func (r *Router) PrefixDELETE(prefix string, handle http.HandlerFunc, options ...interface{})

PrefixDELETE registers a DELETE handler, which matches all routes with the given prefix

func (*Router) PrefixGET

func (r *Router) PrefixGET(prefix string, handle http.HandlerFunc, options ...interface{})

PrefixGET registers a GET handler, which matches all routes with the given prefix

func (*Router) PrefixGETHandler

func (r *Router) PrefixGETHandler(prefix string, handler http.Handler, options ...interface{})

PrefixGETHandler registers a GET handler, which matches all routes with the given prefix

func (*Router) PrefixHEAD

func (r *Router) PrefixHEAD(prefix string, handle http.HandlerFunc, options ...interface{})

PrefixHEAD registers a HEAD handler, which matches all routes with the given prefix

func (*Router) PrefixPOST

func (r *Router) PrefixPOST(prefix string, handle http.HandlerFunc, options ...interface{})

PrefixPOST registers a POST handler, which matches all routes with the given prefix

func (*Router) PrefixPOSTHandler

func (r *Router) PrefixPOSTHandler(prefix string, handler http.Handler, options ...interface{})

PrefixPOSTHandler registers a POST handler, which matches all routes with the given prefix

func (*Router) PrefixPUT

func (r *Router) PrefixPUT(prefix string, handle http.HandlerFunc, options ...interface{})

PrefixPUT registers a PUT handler, which matches all routes with the given prefix

func (*Router) WithPrefix

func (r *Router) WithPrefix(prefix string) *PrefixRouter

WithPrefix return a prefix-router for the given prefix

type Server

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

func New

func New(bind string) (*Server, error)

func (*Server) Addr

func (s *Server) Addr() net.Addr

func (*Server) Close

func (s *Server) Close()

func (*Server) Run

func (s *Server) Run(handler http.Handler) error

func (*Server) RunTLS

func (s *Server) RunTLS(handler http.Handler, certFile, keyFile string) error

func (*Server) Shutdown

func (s *Server) Shutdown(timeout time.Duration)

type SortComponent

type SortComponent struct {
	Name  string    `json:"name"`
	Order SortOrder `json:"order"`
}

func (SortComponent) String

func (sc SortComponent) String() string

type SortComponents

type SortComponents []SortComponent

func (SortComponents) String

func (scs SortComponents) String() string

type SortConfiguration

type SortConfiguration struct {
	Fields     []SortField    `json:"fields,omitempty"`
	Components SortComponents `json:"components,omitempty"`
}

type SortField

type SortField struct {
	Name  string `json:"name"`
	Label string `json:"label"`
}

type SortOrder

type SortOrder string
const (
	SortNone SortOrder = "None"
	SortASC  SortOrder = "ASC"
	SortDESC SortOrder = "DESC"
)

func (SortOrder) IfLess

func (o SortOrder) IfLess(less bool) bool

func (SortOrder) String

func (o SortOrder) String() string

func (SortOrder) Valid

func (o SortOrder) Valid() bool

type StatusWriter

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

func NewStatusWriter

func NewStatusWriter(w http.ResponseWriter) *StatusWriter

func (*StatusWriter) Code

func (sw *StatusWriter) Code() int

func (*StatusWriter) Header

func (sw *StatusWriter) Header() http.Header

func (*StatusWriter) Write

func (sw *StatusWriter) Write(p []byte) (n int, err error)

func (*StatusWriter) WriteHeader

func (sw *StatusWriter) WriteHeader(code int)

type Timing

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

func NewTiming

func NewTiming() *Timing

func (*Timing) Start

func (t *Timing) Start(name string)

func (*Timing) StartAgg

func (t *Timing) StartAgg(name string)

func (*Timing) StopCurrAgg

func (t *Timing) StopCurrAgg()

func (*Timing) Write

func (t *Timing) Write(w http.ResponseWriter)

Jump to

Keyboard shortcuts

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