Documentation ¶
Index ¶
- Constants
- Variables
- func FilteredLogger(flags int, msgs ...string) *log.Logger
- func GetSecureCookie(ctx *Context) *securecookie.SecureCookie
- func H2Client() *http.Client
- func JSONRequest(method, url string, reqData, respData any) (err error)
- type AutoCertHosts
- type AutoCertOpts
- type CacheableResponse
- type CertPair
- type Codec
- type Context
- func (ctx *Context) Bind(out any) error
- func (ctx *Context) BindCodec(c Codec, out any) error
- func (ctx *Context) BindJSON(out any) error
- func (ctx *Context) BindMsgpack(out any) error
- func (ctx *Context) BytesWritten() int
- func (ctx *Context) ClientIP() string
- func (ctx *Context) CloseBody() error
- func (ctx *Context) ContentType() string
- func (ctx *Context) Deadline() (time.Time, bool)
- func (ctx *Context) Done() <-chan struct{}
- func (ctx *Context) Encode(code int, v any) error
- func (ctx *Context) EncodeCodec(c Codec, code int, v any) error
- func (ctx *Context) Err() error
- func (ctx *Context) File(fp string) error
- func (ctx *Context) Finished() bool
- func (ctx *Context) Flush()
- func (ctx *Context) Get(key string) any
- func (ctx *Context) GetCookie(name string) (out string, ok bool)
- func (ctx *Context) GetCookieValue(name string, valDst any) error
- func (ctx *Context) JSON(code int, indent bool, v any) error
- func (ctx *Context) LimitRead(sz int64)
- func (ctx *Context) LogSkipf(skip int, format string, v ...any)
- func (ctx *Context) Logf(format string, v ...any)
- func (ctx *Context) Msgpack(code int, v any) error
- func (ctx *Context) MultipartReader() (*multipart.Reader, error)
- func (ctx *Context) Next()
- func (ctx *Context) NextHandler()
- func (ctx *Context) NextMiddleware()
- func (ctx *Context) Param(key string) string
- func (ctx *Context) Path() string
- func (ctx *Context) Printf(code int, contentType, s string, args ...any) (int, error)
- func (ctx *Context) Query(key string) string
- func (ctx *Context) QueryDefault(key, def string) string
- func (ctx *Context) Read(p []byte) (int, error)
- func (ctx *Context) RemoveCookie(name string)
- func (ctx *Context) ReqHeader(key string) string
- func (ctx *Context) Route() *router.Route
- func (ctx *Context) Set(key string, val any)
- func (ctx *Context) SetContentType(typ string)
- func (ctx *Context) SetCookie(name string, value any, domain string, forceHTTPS bool, duration time.Duration) (err error)
- func (ctx *Context) Status() int
- func (ctx *Context) Value(key any) any
- func (ctx *Context) Write(p []byte) (int, error)
- func (ctx *Context) WriteHeader(s int)
- func (ctx *Context) WriteReader(contentType string, r io.Reader) (int64, error)
- func (ctx *Context) WriteString(p string) (int, error)
- type Decoder
- type DummyResponseWriter
- type Encoder
- type Error
- type GenResponse
- type Group
- func (g *Group) AddRoute(method, path string, handlers ...Handler) Route
- func (g *Group) DELETE(path string, handlers ...Handler) Route
- func (g *Group) DisableRoute(method, path string, disabled bool) bool
- func (g *Group) GET(path string, handlers ...Handler) Route
- func (g *Group) OPTIONS(path string, handlers ...Handler) Route
- func (g *Group) POST(path string, handlers ...Handler) Route
- func (g *Group) PUT(path string, handlers ...Handler) Route
- func (g *Group) Routes() [][3]string
- func (g *Group) Static(path, localPath string, allowListing bool) Route
- func (g *Group) StaticFile(path, localPath string) Route
- func (g *Group) SubGroup(name, path string, mw ...Handler) *Group
- func (g *Group) Use(mw ...Handler)
- type GroupType
- type HTTPError
- type Handler
- func AllowCORS(methods, headers, origins []string, groups ...GroupType) Handler
- func CacheHandler(etag func(ctx *Context) string, ttlDuration time.Duration, handler Handler) Handler
- func HTTPHandler(h http.Handler) Handler
- func HTTPHandlerFunc(h http.HandlerFunc) Handler
- func LogRequests(logJSONRequests bool) Handler
- func ProxyHandler(host string, pathFn func(ctx *Context, path string) (string, error)) Handler
- func RateLimiter(ctx context.Context, limitKey LimitKeyFn, ...) Handler
- func SecureCookie(hashKey, blockKey []byte) Handler
- func StaticDir(dir, paramName string) Handler
- func StaticDirStd(prefix, dir string, allowListing bool) Handler
- func StaticDirWithLimit(dir, paramName string, limit int) Handler
- type JSONCodec
- type JSONResponse
- type LimitKeyFn
- type Limiter
- type Limiters
- type M
- type MixedCodec
- type MsgpCodec
- type MsgpResponse
- type MultiError
- type Option
- func MaxHeaderBytes(v int) Option
- func ReadTimeout(v time.Duration) Option
- func SetCatchPanics(enable bool) Option
- func SetErrLogger(v *log.Logger) Option
- func SetOnReqDone(fn router.OnRequestDone) Option
- func SetProfileLabels(enable bool) Option
- func SetRouterOptions(v *router.Options) Option
- func WriteTimeout(v time.Duration) Option
- type Options
- type PanicHandler
- type PlainTextCodec
- type PlainTextResponse
- type Response
- type Route
- func Delete[CodecT Codec, Resp any, HandlerFn func(ctx *Context) (resp Resp, err error)](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func Get[CodecT Codec, Resp any, HandlerFn func(ctx *Context) (resp Resp, err error)](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func JSONDelete[Resp any, HandlerFn func(ctx *Context) (resp Resp, err error)](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func JSONGet[Resp any, HandlerFn func(ctx *Context) (resp Resp, err error)](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func JSONPatch[Req, Resp any, ...](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func JSONPost[Req, Resp any, ...](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func JSONPut[Req, Resp any, ...](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func MsgpDelete[Resp any, HandlerFn func(ctx *Context) (resp Resp, err error)](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func MsgpGet[Resp any, HandlerFn func(ctx *Context) (resp Resp, err error)](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func MsgpPatch[Req, Resp any, ...](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func MsgpPost[Req, Resp any, ...](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func MsgpPut[Req, Resp any, ...](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func Patch[CodecT Codec, Req, Resp any, ...](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func Post[CodecT Codec, Req, Resp any, ...](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- func Put[CodecT Codec, Req, Resp any, ...](g GroupType, path string, handler HandlerFn, wrapResp bool) Route
- type Server
- func (s *Server) Addrs() (out []string)
- func (s *Server) AllowCORS(path string, allowedMethods ...string)
- func (s *Server) Close() error
- func (s *Server) Closed() bool
- func (s *Server) Logf(f string, args ...any)
- func (s *Server) Run(ctx context.Context, addr string) error
- func (s *Server) RunAutoCert(ctx context.Context, certCacheDir string, domains ...string) error
- func (s *Server) RunAutoCertDyn(ctx context.Context, opts *AutoCertOpts) error
- func (s *Server) RunTLSAndAuto(ctx context.Context, certPairs []CertPair, opts *AutoCertOpts) error
- func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (s *Server) SetKeepAlivesEnabled(v bool)
- func (s *Server) Shutdown(timeout time.Duration) error
- func (s *Server) Swagger() *router.Swagger
Constants ¶
const ( MimeJSON = "application/json" MimeEvent = "text/event-stream" MimeMsgPack = "application/msgpack" MimeXML = "application/xml" MimeJavascript = "application/javascript" MimeHTML = "text/html" MimePlain = "text/plain" MimeBinary = "application/octet-stream" )
Common mime-types
const ( // ErrDir is Returned from ctx.File when the path is a directory not a file. ErrDir = oerrs.String("file is a directory") // ErrInvalidURL gets returned on invalid redirect urls. ErrInvalidURL = oerrs.String("invalid redirect error") // ErrEmptyCallback is returned when a callback is empty ErrEmptyCallback = oerrs.String("empty callback") // ErrEmptyData is returned when the data payload is empty ErrEmptyData = oerrs.String("payload data is empty") )
Variables ¶
var ( ErrBadRequest = NewError(http.StatusBadRequest, "bad request") ErrForbidden = NewError(http.StatusForbidden, "the gates of time are closed") ErrNotFound = NewError(http.StatusNotFound, "not found") ErrTeaPot = NewError(http.StatusTeapot, "I'm a teapot") ErrInternal = NewError(http.StatusInternalServerError, "internal error") ErrNotImpl = NewError(http.StatusNotImplemented, "not implemented") )
var DefaultOpts = Options{ WriteTimeout: time.Minute, ReadTimeout: time.Minute, MaxHeaderBytes: 1 << 20, Logger: log.New(os.Stderr, "gserv: ", 0), }
DefaultOpts are the default options used for creating new servers.
var DefaultPanicHandler = func(ctx *Context, v any, fr *oerrs.Frame) { msg, info := fmt.Sprintf("PANIC in %s %s: %v", ctx.Req.Method, ctx.Path(), v), fmt.Sprintf("at %s %s:%d", fr.Function, fr.File, fr.Line) ctx.Logf("%s (%s)", msg, info) resp := NewJSONErrorResponse(500, "internal server error") _ = ctx.Encode(500, resp) }
Functions ¶
func GetSecureCookie ¶
func GetSecureCookie(ctx *Context) *securecookie.SecureCookie
GetSecureCookie returns the *securecookie.SecureCookie associated with the Context, or nil.
func JSONRequest ¶
Types ¶
type AutoCertHosts ¶
type AutoCertHosts struct {
// contains filtered or unexported fields
}
func NewAutoCertHosts ¶
func NewAutoCertHosts(hosts ...string) *AutoCertHosts
func (*AutoCertHosts) Contains ¶
func (a *AutoCertHosts) Contains(host string) bool
func (*AutoCertHosts) IsAllowed ¶
func (a *AutoCertHosts) IsAllowed(_ context.Context, host string) error
func (*AutoCertHosts) Set ¶
func (a *AutoCertHosts) Set(hosts ...string)
type AutoCertOpts ¶ added in v1.1.3
type AutoCertOpts struct { Hosts autocert.HostPolicy `json:"hosts"` Eab *acme.ExternalAccountBinding `json:"eab"` Email string `json:"email"` CacheDir string `json:"cacheDir"` DirectoryURL string `json:"directoryURL"` }
type CacheableResponse ¶
type CacheableResponse interface {
Cached() Response
}
type CertPair ¶
type CertPair struct { Cert []byte `json:"cert"` Key []byte `json:"key"` Roots [][]byte `json:"roots"` }
CertPair is a pair of (cert, key) files to listen on TLS
func NewCertPair ¶ added in v1.1.3
type Codec ¶
type Context ¶
type Context struct { http.ResponseWriter Codec Codec Req *http.Request ReqQuery url.Values Params router.Params // contains filtered or unexported fields }
Context is the default context passed to handlers it is not thread safe and should never be used outside the handler
func (*Context) Bind ¶
Bind parses the request's body as msgpack, and closes the body. Note that unlike gin.Context.Bind, this does NOT verify the fields using special tags.
func (*Context) BindCodec ¶ added in v1.1.0
BindCodec parses the request's body as msgpack, and closes the body. Note that unlike gin.Context.BindCodec, this does NOT verify the fields using special tags.
func (*Context) BindJSON ¶
BindJSON parses the request's body as json, and closes the body. Note that unlike gin.Context.Bind, this does NOT verify the fields using special tags.
func (*Context) BindMsgpack ¶
BindMsgpoack parses the request's body as msgpack, and closes the body. Note that unlike gin.Context.Bind, this does NOT verify the fields using special tags.
func (*Context) BytesWritten ¶ added in v1.1.0
BytesWritten is the amount of bytes written from the body.
func (*Context) ClientIP ¶
ClientIP returns the current client ip, accounting for X-Real-Ip and X-forwarded-For headers as well.
func (*Context) ContentType ¶
ContentType returns the request's content-type.
func (*Context) EncodeCodec ¶ added in v1.1.0
func (*Context) Finished ¶ added in v1.1.11
Finished returns wither the context is marked as done or not.
func (*Context) GetCookieValue ¶
GetCookieValue unmarshals a cookie, only needed if you stored an object for the cookie not a string.
func (*Context) JSON ¶
JSON outputs a json object, it is highly recommended to return *Response rather than use this directly. calling this function marks the Context as done, meaning any returned responses won't be written out.
func (*Context) Msgpack ¶
Msgpack outputs a msgp object, it is highly recommended to return *Response rather than use this directly. calling this function marks the Context as done, meaning any returned responses won't be written out.
func (*Context) MultipartReader ¶
MultipartReader is like Request.MultipartReader but supports multipart/*, not just form-data
func (*Context) Next ¶
func (ctx *Context) Next()
Next is a QoL function that calls NextMiddleware() then NextHandler() if NextMiddleware() didn't return a response.
func (*Context) NextHandler ¶
func (ctx *Context) NextHandler()
NextHandler is a func to execute all the handlers in the group up until one returns a Response.
func (*Context) NextMiddleware ¶
func (ctx *Context) NextMiddleware()
NextMiddleware is a middleware-only func to execute all the other middlewares in the group and return before the handlers. will panic if called from a handler.
func (*Context) Printf ¶
Printf is a QoL function to handle outputting plain strings with optional fmt.Printf-style formatting. calling this function marks the Context as done, meaning any returned responses won't be written out.
func (*Context) QueryDefault ¶
QueryDefault returns the query key or a default value.
func (*Context) RemoveCookie ¶
RemoveCookie deletes the given cookie and sets its expires date in the past.
func (*Context) Set ¶
Set sets a context value, useful in passing data to other handlers down the chain
func (*Context) SetContentType ¶
SetContentType sets the responses's content-type.
func (*Context) SetCookie ¶
func (ctx *Context) SetCookie(name string, value any, domain string, forceHTTPS bool, duration time.Duration) (err error)
SetCookie sets an http-only cookie using the passed name, value and domain. Returns an error if there was a problem encoding the value. if forceSecure is true, it will set the Secure flag to true, otherwise it sets it based on the connection. if duration == -1, it sets expires to 10 years in the past, if 0 it gets ignored (aka session-only cookie), if duration > 0, the expiration date gets set to now() + duration. Note that for more complex options, you can use http.SetCookie(ctx, &http.Cookie{...}).
func (*Context) WriteHeader ¶
WriteHeader and Write are to implement ResponseWriter and allows ghetto hijacking of http.ServeContent errors, without them we'd end up with plain text errors, we wouldn't want that, would we? WriteHeader implements http.ResponseWriter
func (*Context) WriteReader ¶
WriteReader outputs the data from the passed reader with optional content-type.
type DummyResponseWriter ¶ added in v1.1.0
type DummyResponseWriter struct {
// contains filtered or unexported fields
}
func (*DummyResponseWriter) Bytes ¶ added in v1.1.0
func (d *DummyResponseWriter) Bytes() []byte
func (*DummyResponseWriter) Header ¶ added in v1.1.0
func (d *DummyResponseWriter) Header() http.Header
func (*DummyResponseWriter) Status ¶ added in v1.1.0
func (d *DummyResponseWriter) Status() int
func (*DummyResponseWriter) Write ¶ added in v1.1.0
func (d *DummyResponseWriter) Write(b []byte) (int, error)
func (*DummyResponseWriter) WriteHeader ¶ added in v1.1.0
func (d *DummyResponseWriter) WriteHeader(v int)
type Error ¶
type GenResponse ¶
type GenResponse[CodecT Codec] struct { Data any `json:"data,omitempty"` Errors []Error `json:"errors,omitempty"` Code int `json:"code"` Success bool `json:"success"` }
GenResponse is the default standard api response
func NewErrorResponse ¶
func NewErrorResponse[CodecT Codec](code int, errs ...any) (r *GenResponse[CodecT])
NewJSONErrorResponse returns a new error response. each err can be: 1. string or []byte 2. error 3. Error / *Error 4. another response, its Errors will be appended to the returned Response. 5. MultiError 6. if errs is empty, it will call http.StatusText(code) and set that as the error.
func NewResponse ¶
func NewResponse[CodecT Codec](data any) *GenResponse[CodecT]
func (GenResponse[CodecT]) Cached ¶
func (r GenResponse[CodecT]) Cached() Response
func (*GenResponse[CodecT]) ErrorList ¶
func (r *GenResponse[CodecT]) ErrorList() *oerrs.ErrorList
ErrorList returns an errors.ErrorList of this response's errors or nil. Deprecated: handled using MultiError
func (GenResponse[CodecT]) Status ¶
func (r GenResponse[CodecT]) Status() int
func (GenResponse[CodecT]) WriteToCtx ¶
func (r GenResponse[CodecT]) WriteToCtx(ctx *Context) error
WriteToCtx writes the response to a ResponseWriter
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func (*Group) AddRoute ¶
AddRoute adds a handler (or more) to the specific method and path it is NOT safe to call this once you call one of the run functions
func (*Group) DisableRoute ¶ added in v1.1.0
func (*Group) OPTIONS ¶ added in v1.1.0
OPTIONS is an alias for AddRoute("OPTIONS", path, handlers...).
func (*Group) Routes ¶
Routes returns the current routes set. Each route is returned in the order of group name, method, path.
func (*Group) StaticFile ¶
type Handler ¶
Handler is the default server Handler In a handler chain, returning a non-nil breaks the chain.
func AllowCORS ¶
AllowCORS allows CORS responses. If methods is empty, it will respond with the requested method. If headers is empty, it will respond with the requested headers. If origins is empty, it will respond with the requested origin. will automatically install an OPTIONS handler to each passed group.
func CacheHandler ¶
func HTTPHandler ¶
HTTPHandler returns a Handler from an http.Handler.
func HTTPHandlerFunc ¶
func HTTPHandlerFunc(h http.HandlerFunc) Handler
FromHTTPHandlerFunc returns a Handler from an http.Handler.
func LogRequests ¶
LogRequests is a request logger middleware. If logJSONRequests is true, it'll attempt to parse the incoming request's body and output it to the log.
func ProxyHandler ¶ added in v1.1.0
func RateLimiter ¶ added in v1.1.7
func SecureCookie ¶
SecureCookie is a middleware to enable SecureCookies. For more details check `go doc securecookie.New`
func StaticDirStd ¶
StaticDirStd is a QoL wrapper for http.FileServer(http.Dir(dir)).
func StaticDirWithLimit ¶
StaticDirWithLimit returns a handler that handles serving static files. paramName is the path param, for example: s.GET("/s/*fp", StaticDirWithLimit("./static/", "fp", 1000)). if limit is > 0, it will only ever serve N files at a time. BUG: returns 0 size for some reason
type JSONResponse ¶
type JSONResponse = GenResponse[JSONCodec]
func NewJSONErrorResponse ¶
func NewJSONErrorResponse(code int, errs ...any) *JSONResponse
func NewJSONResponse ¶
func NewJSONResponse(data any) *JSONResponse
NewJSONResponse returns a new (json) success response (code 200) with the specific data
func ReadJSONResponse ¶
func ReadJSONResponse(rc io.ReadCloser, dataValue any) (r *JSONResponse, err error)
ReadJSONResponse reads a response from an io.ReadCloser and closes the body. dataValue is the data type you're expecting, for example:
r, err := ReadJSONResponse(res.Body, &map[string]*Stats{})
type LimitKeyFn ¶ added in v1.1.7
type Limiter ¶ added in v1.1.7
type Limiter struct {
// contains filtered or unexported fields
}
func NewLimiter ¶ added in v1.1.7
func (*Limiter) Allowed ¶ added in v1.1.7
Allowed returns the duration until the next action is allowed and an error if it's longer than 0
func (*Limiter) LastAction ¶ added in v1.1.7
func (*Limiter) RequestsLeft ¶ added in v1.1.7
type Limiters ¶ added in v1.1.7
type Limiters struct {
// contains filtered or unexported fields
}
func NewLimiters ¶ added in v1.1.7
type MixedCodec ¶
type MixedCodec[Dec, Enc Codec] struct { // contains filtered or unexported fields }
func (MixedCodec[Dec, Enc]) ContentType ¶
func (m MixedCodec[Dec, Enc]) ContentType() string
type MsgpResponse ¶
type MsgpResponse = GenResponse[MsgpCodec]
func NewMsgpErrorResponse ¶
func NewMsgpErrorResponse(code int, errs ...any) *MsgpResponse
func NewMsgpResponse ¶
func NewMsgpResponse(data any) *MsgpResponse
NewMsgpResponse returns a new (msgpack) success response (code 200) with the specific data
type MultiError ¶
type MultiError []error
MultiError handles returning multiple errors.
func (MultiError) Error ¶
func (me MultiError) Error() string
func (*MultiError) Push ¶
func (me *MultiError) Push(err error)
Push adds an error to the MultiError slice if err != nil.
type Option ¶
type Option = func(opt *Options)
Option is a func to set internal server Options.
func MaxHeaderBytes ¶
MaxHeaderBytes sets the max size of headers on the server. see http.Server.MaxHeaderBytes
func ReadTimeout ¶
ReadTimeout sets the read timeout on the server. see http.Server.ReadTimeout
func SetCatchPanics ¶
SetNoCatchPanics toggles catching panics in handlers.
func SetErrLogger ¶
SetErrLogger sets the error logger on the server.
func SetOnReqDone ¶
func SetOnReqDone(fn router.OnRequestDone) Option
func SetProfileLabels ¶
func SetRouterOptions ¶
SetRouterOptions sets gserv/router.Options on the server.
func WriteTimeout ¶
WriteTimeout sets the write timeout on the server. see http.Server.WriteTimeout
type Options ¶
type Options struct { Logger *log.Logger RouterOptions *router.Options ReadTimeout time.Duration WriteTimeout time.Duration MaxHeaderBytes int CatchPanics bool }
Options allows finer control over the gserv
type PlainTextCodec ¶
type PlainTextCodec struct{}
func (PlainTextCodec) ContentType ¶
func (PlainTextCodec) ContentType() string
type PlainTextResponse ¶
type PlainTextResponse = GenResponse[PlainTextCodec]
func NewPlainErrorResponse ¶
func NewPlainErrorResponse(code int, errs ...any) *PlainTextResponse
func NewPlainResponse ¶
func NewPlainResponse(data any) *PlainTextResponse
NewJSONResponse returns a new (json) success response (code 200) with the specific data
type Response ¶
Response represents a generic return type for http responses.
var ( RespMethodNotAllowed Response = NewJSONErrorResponse(http.StatusMethodNotAllowed).Cached() RespNotFound Response = NewJSONErrorResponse(http.StatusNotFound).Cached() RespForbidden Response = NewJSONErrorResponse(http.StatusForbidden).Cached() RespBadRequest Response = NewJSONErrorResponse(http.StatusBadRequest).Cached() RespOK Response = NewJSONResponse("OK").Cached() RespEmpty Response = CachedResponse(http.StatusNoContent, "", nil) RespPlainOK Response = CachedResponse(http.StatusOK, "", nil) RespRedirectRoot Response = Redirect("/", false) // Break can be returned from a handler to break a handler chain. // It doesn't write anything to the connection. // if you reassign this, a wild animal will devour your face. Break Response = &cachedResp{code: -1} )
Common responses
func PlainResponse ¶
func Redirect ¶
Redirect returns a redirect Response. if perm is false it uses http.StatusFound (302), otherwise http.StatusMovedPermanently (302)
func RedirectWithCode ¶
RedirectWithCode returns a redirect Response with the specified status code.
type Route ¶
func JSONDelete ¶
func MsgpDelete ¶
type Server ¶
type Server struct { Group PanicHandler NotFoundHandler func(ctx *Context) NoCompression bool // used by proxies // contains filtered or unexported fields }
Server is the main server
func NewWithOpts ¶
NewWithOpts allows passing the Options struct directly
func (*Server) Addrs ¶
Addrs returns all the listening addresses used by the underlying http.Server(s).
func (*Server) AllowCORS ¶
AllowCORS is an alias for s.AddRoute("OPTIONS", path, AllowCORS(allowedMethods...))
func (*Server) Close ¶
Close immediately closes all the active underlying http servers and connections.
func (*Server) RunAutoCert ¶
RunAutoCert enables automatic support for LetsEncrypt, using the optional passed domains list. certCacheDir is where the certificates will be cached, defaults to "./autocert". Note that it must always run on *BOTH* ":80" and ":443" so the addr param is omitted.
func (*Server) RunAutoCertDyn ¶ added in v1.1.0
func (s *Server) RunAutoCertDyn(ctx context.Context, opts *AutoCertOpts) error
RunAutoCertDyn enables automatic support for LetsEncrypt, using a dynamic HostPolicy. certCacheDir is where the certificates will be cached, defaults to "./autocert". Note that it must always run on *BOTH* ":80" and ":443" so the addr param is omitted.
func (*Server) RunTLSAndAuto ¶
RunTLSAndAuto allows using custom certificates and autocert together. It will always listen on both :80 and :443
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP allows using the server in custom scenarios that expects an http.Handler.
func (*Server) SetKeepAlivesEnabled ¶
SetKeepAlivesEnabled controls whether HTTP keep-alives are enabled. By default, keep-alives are always enabled.