http

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2025 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorHandler = func(c *Context, err error) {
	if err == nil {
		return
	}
	e := ierr.FromError(err)
	_ = c.JSON(e.Status(), e)
}
View Source
var PanicHandler = func(c *Context, rec any) {
	if rec == nil {
		return
	}
	slog.Error("[%s] %v", osutil.CallerString(3), rec, slog.String("stack", osutil.Stack(2)), slog.GetAttrs(c))
	err, ok := rec.(error)
	if !ok {
		err = fmt.Errorf("%v", rec)
	}
	ErrorHandler(c, err)
}
View Source
var StripPrefix = http.StripPrefix

Functions

func FileServer

func FileServer(r Router, path string, fs fs.FS)

Types

type Context

type Context struct {
	Req *Request
	Res ResponseWriter
	// contains filtered or unexported fields
}

func NewContext

func NewContext(w ResponseWriter, r *Request) *Context

func (*Context) BindForm

func (c *Context) BindForm(obj any) error

func (*Context) BindHeader

func (c *Context) BindHeader(obj any) error

func (*Context) BindJSON

func (c *Context) BindJSON(obj any) error

func (*Context) BindMultiForm

func (c *Context) BindMultiForm(obj any) error

func (*Context) BindPostForm

func (c *Context) BindPostForm(obj any) error

func (*Context) BindQuery

func (c *Context) BindQuery(obj any) error

func (*Context) BindXML

func (c *Context) BindXML(obj any) error

func (*Context) Context

func (c *Context) Context() context.Context

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (c *Context) Done() <-chan struct{}

func (*Context) Err

func (c *Context) Err() error

func (*Context) GetContentType

func (c *Context) GetContentType() string

func (*Context) GetHeader

func (c *Context) GetHeader(key string) config.Value

func (*Context) GetHeaders

func (c *Context) GetHeaders(key string) []string

func (*Context) GetParam

func (c *Context) GetParam(key string) config.Value

func (*Context) GetParams

func (c *Context) GetParams() map[string]string

func (*Context) GetQueries

func (c *Context) GetQueries(key string) []string

func (*Context) GetQuery

func (c *Context) GetQuery(key string) config.Value

func (*Context) GetRawBody

func (c *Context) GetRawBody() ([]byte, error)

func (*Context) GetRoutePattern

func (c *Context) GetRoutePattern() string

func (*Context) HTML

func (c *Context) HTML(status int, tpl template.Template, data any, name ...string) error

func (*Context) Header

func (c *Context) Header(key, value string)

func (*Context) JSON

func (c *Context) JSON(status int, v any) error

func (*Context) MustGetRawBody

func (c *Context) MustGetRawBody() []byte

func (*Context) Redirect

func (c *Context) Redirect(status int, url string)

func (*Context) Render

func (c *Context) Render(status int, contentType string, bs []byte) error

func (*Context) Status

func (c *Context) Status(status int)

func (*Context) TEXT

func (c *Context) TEXT(status int, text string) error

func (*Context) Value

func (c *Context) Value(key any) any

func (*Context) XML

func (c *Context) XML(status int, v any) error

type Handler

type Handler = http.Handler

type HandlerCtx

type HandlerCtx func(c *Context) error

func (HandlerCtx) ServeHTTP

func (hc HandlerCtx) ServeHTTP(w ResponseWriter, r *Request)

type HandlerFunc

type HandlerFunc = http.HandlerFunc

type Middleware

type Middleware = func(next Handler) Handler

type Mux

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

func NewMux

func NewMux() *Mux

func (*Mux) Group

func (m *Mux) Group(fn RouterFunc) Router

func (*Mux) Handle

func (m *Mux) Handle(pattern string, h Handler)

func (*Mux) HandleCtx

func (m *Mux) HandleCtx(pattern string, h HandlerCtx)

func (*Mux) HandleFunc

func (m *Mux) HandleFunc(pattern string, h HandlerFunc)

func (*Mux) Mount

func (m *Mux) Mount(pattern string, h Handler)

func (*Mux) Route

func (m *Mux) Route(pattern string, fn RouterFunc) Router

func (*Mux) ServeHTTP

func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Mux) Use

func (m *Mux) Use(middlewares ...Middleware)

func (*Mux) With

func (m *Mux) With(middlewares ...Middleware) Router

type Request

type Request = http.Request

type ResponseWriter

type ResponseWriter = http.ResponseWriter

type Router

type Router interface {
	Handler

	Use(middlewares ...Middleware)
	With(middlewares ...Middleware) Router

	Group(fn RouterFunc) Router
	Route(pattern string, fn RouterFunc) Router
	Mount(pattern string, h Handler)

	Handle(pattern string, h Handler)
	HandleFunc(pattern string, h HandlerFunc)
	HandleCtx(pattern string, h HandlerCtx)
}

type RouterFunc

type RouterFunc = func(r Router)

type Server

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

func NewServer

func NewServer() *Server

func (*Server) Start

func (s *Server) Start(ln net.Listener) error

func (*Server) Stop

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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