ws

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: MIT Imports: 21 Imported by: 4

Documentation

Overview

Package ws provides a simple web server.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotModified      = NewError(http.StatusNotModified)
	ErrBadRequest       = NewError(http.StatusBadRequest)
	ErrUnauthorized     = NewError(http.StatusUnauthorized)
	ErrForbidden        = NewError(http.StatusForbidden)
	ErrNotFound         = NewError(http.StatusNotFound)
	ErrMethodNotAllowed = NewError(http.StatusMethodNotAllowed)
	ErrTooManyRequests  = NewError(http.StatusTooManyRequests)
)

Errors.

Functions

func RealIP added in v0.1.2

func RealIP(r *http.Request) (netip.Addr, error)

RealIP returns the real ip of the client.

Types

type Checker added in v0.1.2

type Checker interface {
	Check() error
}

Checker represents a model checker.

type Error added in v0.1.2

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

Error represents a custom error.

func Errorf added in v0.1.2

func Errorf(format string, vs ...any) *Error

Errorf formats according to a format specifier and returns the string as a value that satisfies error.

func NewError added in v0.1.2

func NewError(code int, vs ...any) *Error

NewError creates a new custom error by http code.

func (*Error) Error added in v0.1.2

func (a *Error) Error() string

Error implements the error interface.

func (*Error) Unwrap added in v0.1.2

func (a *Error) Unwrap() error

Unwrap returns underline error.

func (*Error) Wrap added in v0.1.2

func (a *Error) Wrap(err error) *Error

Wrap wraps the err.

type Router

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

Router represents a router.

func (*Router) MaxBodyBytes added in v0.1.2

func (a *Router) MaxBodyBytes(n int64)

MaxBodyBytes controls the maximum number of bytes the decoder will read the body.

func (*Router) MustProvide added in v0.1.2

func (a *Router) MustProvide(constructor any, itype any)

MustProvide is like Provide but panics if has error.

func (*Router) MustRegisterFS added in v0.1.2

func (a *Router) MustRegisterFS(key string, fsys fs.FS)

MustRegisterFS registers the fs, and panic if any error.

func (*Router) Provide added in v0.1.2

func (a *Router) Provide(constructor any, itype any) error

Provide teaches the injector how to build values and expresses their dependencies.

func (*Router) Redirect added in v0.1.2

func (a *Router) Redirect(opath, npath string)

Redirect redirects opath to npath.

func (*Router) Register added in v0.1.2

func (a *Router) Register(key string, rcvr any, methods ...string)

Register registers the receiver's methods.

func (*Router) RegisterFN added in v0.1.2

func (a *Router) RegisterFN(key string, fn any, methods ...string)

RegisterFN registers the function handler.

func (*Router) RegisterFS added in v0.1.2

func (a *Router) RegisterFS(key string, fsys fs.FS) error

RegisterFS registers the fs.

func (*Router) Route

func (a *Router) Route(keys ...string) *Router

Route returns the sub router.

type Server

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

Server represents a web server.

func New

func New(injector *di.Injector) *Server

New creates a new server.

func (*Server) Addr added in v0.0.3

func (a *Server) Addr(addr string) *Server

Addr optionally specifies the TCP address for the server to listen on.

func (*Server) Config added in v0.0.3

func (a *Server) Config(f func(s *http.Server)) *Server

Config configures the raw http.Server.

func (*Server) IdleTimeout added in v0.0.3

func (a *Server) IdleTimeout(d time.Duration) *Server

IdleTimeout is the maximum amount of time to wait for the next request when keep-alives are enabled.

func (*Server) Logger added in v0.1.2

func (a *Server) Logger(logger *log.Logger) *Server

Logger optionally specifies the logger.

func (*Server) MaxBodyBytes added in v0.1.2

func (a *Server) MaxBodyBytes(n int64) *Server

MaxBodyBytes controls the maximum number of bytes the decoder will read the body.

func (*Server) MaxHeaderBytes added in v0.0.3

func (a *Server) MaxHeaderBytes(n int) *Server

MaxHeaderBytes controls the maximum number of bytes the server will read parsing the request header's keys and values.

func (*Server) ReadHeaderTimeout added in v0.0.3

func (a *Server) ReadHeaderTimeout(d time.Duration) *Server

ReadHeaderTimeout is the amount of time allowed to read request headers.

func (*Server) ReadTimeout added in v0.0.3

func (a *Server) ReadTimeout(d time.Duration) *Server

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.

func (*Server) Start

func (a *Server) Start(ctx context.Context, wg *sync.WaitGroup)

Start starts the server.

func (*Server) TLS added in v0.0.3

func (a *Server) TLS(certfile, keyfile string) *Server

TLS sets the certfile and keyfile for TLS.

func (*Server) WriteTimeout added in v0.0.3

func (a *Server) WriteTimeout(d time.Duration) *Server

WriteTimeout is the maximum duration before timing out writes of the response.

Jump to

Keyboard shortcuts

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