Handler type

Type Definition:

any

Middleware type

Type Definition:

func(Handler) Handler

Engine interface

Methods:

Handle


Parameters:
  • method string
  • path string
  • h Handler

Use


Parameters:
  • mw Middleware

Group


Parameters:
  • prefix string

Returns:
  • Engine

Serve


Parameters:
  • addr string

Returns:
  • error

Shutdown


Parameters:
  • ctx context.Context

Returns:
  • error

Unwrap


Returns:
  • any

fastGroup struct

Fields:

  • g (*router.Group)

Methods:

Handle


Parameters:
  • m string
  • p string
  • h Handler

References:


Show/Hide Method Body
{
	fg.g.Handle(m, p, h.(fasthttp.RequestHandler))
}

Use


Parameters:
  • Middleware

References:


Show/Hide Method Body
{}

Group


Parameters:
  • prefix string

Returns:
  • Engine

References:


Show/Hide Method Body
{ return &fastGroup{g: fg.g.Group(prefix)} }

Serve


Parameters:
  • string

Returns:
  • error

Show/Hide Method Body
{ return nil }

Shutdown


Parameters:
  • context.Context

Returns:
  • error

Show/Hide Method Body
{ return nil }

Unwrap


Returns:
  • any

Show/Hide Method Body
{ return fg.g }

FastHTTP struct

Fields:

  • r (*router.Router)
  • mwChain ([]Middleware)
  • srv (*fasthttp.Server)

Methods:

Handle


Parameters:
  • m string
  • p string
  • h Handler

References:


Show/Hide Method Body
{
	final := h.(fasthttp.RequestHandler)
	for i := len(f.mwChain) - 1; i >= 0; i-- {
		final = f.mwChain[i](final).(fasthttp.RequestHandler)
	}
	f.r.Handle(m, p, final)
}

Use


Parameters:
  • mw Middleware

References:


Show/Hide Method Body
{ f.mwChain = append(f.mwChain, mw) }

Group


Parameters:
  • prefix string

Returns:
  • Engine

References:


Show/Hide Method Body
{
	return &fastGroup{g: f.r.Group(prefix)}
}

Serve


Parameters:
  • addr string

Returns:
  • error

Show/Hide Method Body
{
	f.srv = &fasthttp.Server{Handler: f.r.Handler}
	return f.srv.ListenAndServe(addr)
}

Shutdown


Parameters:
  • ctx context.Context

Returns:
  • error

Show/Hide Method Body
{
	if f.srv == nil {
		return nil
	}
	return f.srv.ShutdownWithContext(ctx)
}

Unwrap


Returns:
  • any

Show/Hide Method Body
{ return f.r }

NewFastHTTP function

Returns:

  • *FastHTTP
Show/Hide Function Body
{
	return &FastHTTP{r: router.New()}
}

StdHTTP struct

Fields:

  • mux (*http.ServeMux)
  • mwChain ([]Middleware)
  • srv (*http.Server)

Methods:

Handle


Parameters:
  • m string
  • p string
  • h Handler

References:


Show/Hide Method Body
{
	final := h.(http.Handler)
	for i := len(s.mwChain) - 1; i >= 0; i-- {
		final = s.mwChain[i](final).(http.Handler)
	}

	switch m {
	case http.MethodGet:
		s.mux.Handle(p, final)
	default:
		s.mux.HandleFunc(p, func(w http.ResponseWriter, r *http.Request) {
			if r.Method != m {
				http.NotFound(w, r)
				return
			}
			final.ServeHTTP(w, r)
		})
	}
}

Use


Parameters:
  • mw Middleware

References:


Show/Hide Method Body
{ s.mwChain = append(s.mwChain, mw) }

Group


Parameters:
  • prefix string

Returns:
  • Engine

References:


Show/Hide Method Body
{
	sub := NewStdHTTP()
	sub.mwChain = s.mwChain
	s.mux.Handle(prefix+"/", http.StripPrefix(prefix, sub.mux))
	return sub
}

Serve


Parameters:
  • addr string

Returns:
  • error

Show/Hide Method Body
{
	s.srv = &http.Server{Addr: addr, Handler: s.mux}
	return s.srv.ListenAndServe()
}

Shutdown


Parameters:
  • ctx context.Context

Returns:
  • error

Show/Hide Method Body
{
	if s.srv == nil {
		return nil
	}
	return s.srv.Shutdown(ctx)
}

Unwrap


Returns:
  • any

Show/Hide Method Body
{ return s.mux }

NewStdHTTP function

Returns:

  • *StdHTTP
Show/Hide Function Body
{
	return &StdHTTP{mux: http.NewServeMux()}
}

context import

Import example:

import "context"

context import

Import example:

import "context"

github.com/fasthttp/router import

Import example:

import "github.com/fasthttp/router"

github.com/valyala/fasthttp import

Import example:

import "github.com/valyala/fasthttp"

context import

Import example:

import "context"

net/http import

Import example:

import "net/http"