pack

package
v0.0.0-...-a180e12 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LiveReloadWSPort is the websocket port for the SSR live reload server.
	LiveReloadWSPort = "12450"

	// LiveReloadPath is the websocket path for the SSR live reload server.
	LiveReloadPath = "/reload"
)

Variables

This section is empty.

Functions

func CSRFProtect

func CSRFProtect(config *support.Config) []func(next http.Handler) http.Handler

func Recoverer

func Recoverer(logger *support.Logger) func(next http.Handler) http.Handler

Recoverer is a middleware that recovers from panics, logs the panic (and a backtrace), and returns a HTTP 500 (Internal Server Error) status if possible.

func RequestLogger

func RequestLogger(config *support.Config, logger *support.Logger) func(next http.Handler) http.Handler

RequestLogger prints out the request information.

Types

type Context

type Context = chi.Context

Context is the default routing context set on the root node of a request context to track route patterns, URL parameters and an optional routing path.

type Middlewares

type Middlewares = chi.Middlewares

Middlewares type is a slice of standard middleware handlers with methods to compose middleware chains and http.Handler's.

type Mux

type Mux struct {
	*chi.Mux
}

Mux provides the routing logic.

func NewRouter

func NewRouter() *Mux

NewRouter returns a new object that implements the Router interface.

func (*Mux) Group

func (m *Mux) Group(fn func(r Router)) 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.

func (*Mux) Handle

func (m *Mux) Handle(pattern string, handler http.Handler)

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

func (*Mux) HandleFunc

func (m *Mux) HandleFunc(pattern string, handlerFn http.HandlerFunc)

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

func (*Mux) Match

func (m *Mux) Match(ctx *Context, method, path string) bool

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.

func (*Mux) Middlewares

func (m *Mux) Middlewares() Middlewares

Middlewares returns a slice of middleware handler functions.

func (*Mux) Mount

func (m *Mux) Mount(pattern string, handler http.Handler)

Mount attaches another http.Handler or chi Router as a subrouter along a routing path. It's very useful to split up a large API as many independent routers and compose them as a single service using Mount.

Note that Mount() simply sets a wildcard along the `pattern` that will continue routing at the `handler`, which in most cases is another chi.Router. As a result, if you define two Mount() routes on the exact same pattern the mount will panic.

func (*Mux) Route

func (m *Mux) Route(pattern string, fn func(r Router)) 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.

func (*Mux) Routes

func (m *Mux) Routes() []Route

Routes returns a slice of routing information from the tree, useful for traversing available routes of a router.

func (*Mux) Use

func (m *Mux) 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 (*Mux) With

func (m *Mux) With(middlewares ...func(http.Handler) http.Handler) Router

With adds inline middlewares for an endpoint handler.

type Route

type Route = chi.Route

Route describes the details of a routing handler.

type Router

type Router = chi.Router

Router consists of the core routing methods.

type SPAConfig

type SPAConfig struct {
	BuildFolder string
	DevURL      string
	Root        string
}

SPAConfig defines the development web server URL for debug build and embed FS path for release build.

type Server

type Server struct {
	SPAConfigs []SPAConfig
	*Mux
	*http.Server
	// contains filtered or unexported fields
}

Server processes the HTTP requests.

func NewAppServer

func NewAppServer(embedFS embed.FS, config *support.Config, logger *support.Logger) *Server

NewAppServer initializes the Server instance with built-in middleware.

func NewServer

func NewServer(embedFS embed.FS, config *support.Config, logger *support.Logger) *Server

NewServer initializes the Server instance without built-in middleware.

func (*Server) Info

func (s *Server) Info() []string

Info returns the server info.

func (*Server) SWFallbackDenyList

func (s *Server) SWFallbackDenyList() string

SWFallbackDenyList generates the fallback deny list for service worker which is basically a list of GET routes that are defined on the server-side.

func (*Server) ServeSPA

func (s *Server) ServeSPA(endpoint string, config SPAConfig)

ServeSPA comes in 2 modes:

When it's debug build, it serves the endpoint by reverse proxying the frontend web server URL.

When it's release build, it serves the endpoint using the embedded file system.

Jump to

Keyboard shortcuts

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