Documentation ¶
Overview ¶
Package ws provides a simple web server.
Index ¶
- Variables
- func Compress(data []byte) ([]byte, error)
- func RealIP(r *http.Request) (netip.Addr, error)
- type Checker
- type Error
- type Router
- func (a *Router) AddCreator(creator di.Creator) *Router
- func (a *Router) AddScoped(constructor any, itype any) *Router
- func (a *Router) AddShared(constructor any, itype any) *Router
- func (a *Router) AddValue(value any, itype any) *Router
- func (a *Router) Invoke(function any) (di.Result, error)
- func (a *Router) Redirect(p string, url string) *Router
- func (a *Router) Register(p string, rcvr any, methods ...string) *Router
- func (a *Router) RegisterData(p string, data []byte, modtime time.Time) *Router
- func (a *Router) RegisterFS(p string, fsys fs.FS) *Router
- func (a *Router) RegisterFunc(p string, fn any, methods ...string) *Router
- func (a *Router) Route(p string) *Router
- type Server
- func (a *Server) Addr(addr string) *Server
- func (a *Server) Config(fn func(s *http.Server)) *Server
- func (a *Server) IdleTimeout(d time.Duration) *Server
- func (a *Server) Limiter(freq int, dur time.Duration, cap int) *Server
- func (a *Server) Logger(logger *log.Logger) *Server
- func (a *Server) MaxBodyBytes(n int) *Server
- func (a *Server) MaxHeaderBytes(n int) *Server
- func (a *Server) ReadHeaderTimeout(d time.Duration) *Server
- func (a *Server) ReadTimeout(d time.Duration) *Server
- func (a *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (a *Server) Start(ctx context.Context, wg *sync.WaitGroup) error
- func (a *Server) TLS(certfile, keyfile string) *Server
- func (a *Server) WriteTimeout(d time.Duration) *Server
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotModified = NewError(http.StatusNotModified) ErrBadRequest = NewError(http.StatusBadRequest) ErrForbidden = NewError(http.StatusForbidden) ErrNotFound = NewError(http.StatusNotFound) ErrMethodNotAllowed = NewError(http.StatusMethodNotAllowed) ErrTooManyRequests = NewError(http.StatusTooManyRequests) )
Errors.
Functions ¶
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represents a custom error.
func Errorf ¶
Errorf formats according to a format specifier and returns the string as a value that satisfies error.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router represents a router.
func (*Router) AddCreator ¶ added in v0.1.1
AddCreator adds the creator.
func (*Router) Invoke ¶ added in v0.1.1
Invoke runs the given function after instantiating its dependencies.
func (*Router) RegisterData ¶
RegisterData registers the data.
func (*Router) RegisterFS ¶
RegisterFS registers the fs.
func (*Router) RegisterFunc ¶
RegisterFunc registers the function handler.
type Server ¶
type Server struct { *Router // contains filtered or unexported fields }
Server represents a web server.
func (*Server) IdleTimeout ¶
IdleTimeout is the maximum amount of time to wait for the next request when keep-alives are enabled.
func (*Server) MaxBodyBytes ¶
MaxBodyBytes controls the maximum number of bytes the decoder will read the body.
func (*Server) MaxHeaderBytes ¶
MaxHeaderBytes controls the maximum number of bytes the server will read parsing the request header's keys and values.
func (*Server) ReadHeaderTimeout ¶
ReadHeaderTimeout is the amount of time allowed to read request headers.
func (*Server) ReadTimeout ¶
ReadTimeout is the maximum duration for reading the entire request, including the body.
func (*Server) ServeHTTP ¶
func (a *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP should write reply headers and data to the ResponseWriter and then return.