chi

package
v1.15.5 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PluginsRoot = root + ".plugins"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Middlewares []func(http.Handler) http.Handler
	Handlers    []ConfigHandler
	Routes      []ConfigRouter
}

Config represents chi plugin configuration.

type ConfigHandler

type ConfigHandler struct {
	Handler http.Handler
	Pattern string
}

ConfigHandler represents chi handler configuration.

type ConfigRouter

type ConfigRouter struct {
	Method      string
	HandlerFunc http.HandlerFunc
	Pattern     string
}

ConfigRouter represents chi router configuration.

type Plugin

type Plugin func(context.Context, *chi.Mux) (*Config, error)

Plugin defines a function to process plugin.

type Server

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

Server represents a chi http server.

func NewServer

func NewServer(ctx context.Context, plugins ...Plugin) *Server

NewServer creates a new http server for chi with plugins.

func NewServerWithConfigPath

func NewServerWithConfigPath(ctx context.Context, path string, plugins ...Plugin) (*Server, error)

NewServer creates a new http server for chi with options from path and plugins.

func NewServerWithOptions

func NewServerWithOptions(ctx context.Context, opts *server.Options, plugins ...Plugin) *Server

NewServer creates a new http server for chi with options and plugins

func (*Server) Connect

func (s *Server) Connect(pattern string, handlerFn http.HandlerFunc)

Connect adds the route `pattern` that matches a CONNECT http method to execute the `handlerFn` http.HandlerFunc.

func (*Server) Delete

func (s *Server) Delete(pattern string, handlerFn http.HandlerFunc)

Delete adds the route `pattern` that matches a DELETE http method to execute the `handlerFn` http.HandlerFunc.

func (*Server) Get

func (s *Server) Get(pattern string, handlerFn http.HandlerFunc)

Get adds the route `pattern` that matches a GET http method to execute the `handlerFn` http.HandlerFunc.

func (*Server) Group

func (s *Server) Group(fn func(r chi.Router))

Group creates a new inline-Mux with a fresh middleware stack. It's useful for a group of handlers along the same routing path that use an additional set of middlewares. See _examples/.

func (*Server) Handle

func (s *Server) Handle(pattern string, handler http.Handler)

Handle adds the route `pattern` that matches any http method to execute the `handler` http.Handler.

func (*Server) HandleFunc

func (s *Server) HandleFunc(pattern string, handlerFn http.HandlerFunc)

HandleFunc adds the route `pattern` that matches any http method to execute the `handlerFn` http.HandlerFunc.

func (*Server) Head

func (s *Server) Head(pattern string, handlerFn http.HandlerFunc)

Head adds the route `pattern` that matches a HEAD http method to execute the `handlerFn` http.HandlerFunc.

func (*Server) HttpServer

func (s *Server) HttpServer() *http.Server

HtpServer returns the underlying http server.

func (*Server) Match

func (s *Server) Match(ctx *chi.Context, method string, path string)

Match searches the routing tree for a handler that matches the method/path. It's similar to routing a http request, but without executing the handler thereafter.

Note: the *Context state is updated during execution, so manage the state carefully or make a NewRouteContext().

func (*Server) Method

func (s *Server) Method(method string, pattern string, handler http.Handler)

Method adds the route `pattern` that matches `method` http method to execute the `handler` http.Handler.

func (*Server) MethodFunc

func (s *Server) MethodFunc(method string, pattern string, handlerFn http.HandlerFunc)

MethodFunc adds the route `pattern` that matches `method` http method to execute the `handlerFn` http.HandlerFunc.

func (*Server) Mux

func (s *Server) Mux() *chi.Mux

Mux returns the chi http multiplexer.

func (*Server) Options

func (s *Server) Options(pattern string, handlerFn http.HandlerFunc)

Options adds the route `pattern` that matches a OPTIONS http method to execute the `handlerFn` http.HandlerFunc.

func (*Server) Patch

func (s *Server) Patch(pattern string, handlerFn http.HandlerFunc)

Patch adds the route `pattern` that matches a PATCH http method to execute the `handlerFn` http.HandlerFunc.

func (*Server) Post

func (s *Server) Post(pattern string, handlerFn http.HandlerFunc)

Post adds the route `pattern` that matches a POST http method to execute the `handlerFn` http.HandlerFunc.

func (*Server) Put

func (s *Server) Put(pattern string, handlerFn http.HandlerFunc)

Put adds the route `pattern` that matches a PUT http method to execute the `handlerFn` http.HandlerFunc.

func (*Server) Route

func (s *Server) Route(pattern string, fn func(r chi.Router))

Route creates a new Mux with a fresh middleware stack and mounts it along the `pattern` as a subrouter. Effectively, this is a short-hand call to Mount. See _examples/.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context)

Serve handles requests on incoming connections.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context)

Shutdown gracefully shuts down the server without interrupting any active connections.

func (*Server) Trace

func (s *Server) Trace(pattern string, handlerFn http.HandlerFunc)

Trace adds the route `pattern` that matches a TRACE http method to execute the `handlerFn` http.HandlerFunc.

func (*Server) Use

func (s *Server) Use(middlewares ...func(http.Handler) http.Handler)

Use appends a middleware handler to the Mux middleware stack.

The middleware stack for any Mux will execute before searching for a matching route to a specific handler, which provides opportunity to respond early, change the course of the request execution, or set request-scoped values for the next http.Handler.

func (*Server) With

func (s *Server) With(middlewares ...func(http.Handler) http.Handler) chi.Router

With adds inline middlewares for an endpoint handler.

Jump to

Keyboard shortcuts

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