router

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthRoute

func AuthRoute(h AuthHandler, w http.ResponseWriter, r *http.Request, authType AuthType) http.HandlerFunc

AuthRoute populates the custom AuthHandler args for our route handlers

func GetField

func GetField(r *http.Request, index int) string

GetField is a helper function for handlers to get parameters from url

Types

type AuthHandler

type AuthHandler func(user *models.User, w http.ResponseWriter, r *http.Request) http.HandlerFunc

AuthHandler is the extended handler function that our API routes use

type AuthType

type AuthType int
const (
	Public AuthType = iota
	User
	Moderator
	Admin
)

func (AuthType) String

func (s AuthType) String() string

type ContextAdapter

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

func (*ContextAdapter) ServeHTTP

func (ca *ContextAdapter) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type ContextHandler

type ContextHandler interface {
	ServeHTTPContext(context.Context, http.ResponseWriter, *http.Request)
}

type ContextHandlerFunc

type ContextHandlerFunc func(context.Context, http.ResponseWriter, *http.Request)

func (ContextHandlerFunc) ServeHTTPContext

func (h ContextHandlerFunc) ServeHTTPContext(ctx context.Context, rw http.ResponseWriter, req *http.Request)

type Route

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

type Router

type Router struct {
	MethodNotAllowed http.HandlerFunc
	NotFound         http.HandlerFunc
	WebsocketHandler http.HandlerFunc
	// Function to handle panics recovered from http handlers.
	// Used to keep the server from crashing because of un-recovered panics.
	PanicHandler func(http.ResponseWriter, *http.Request, interface{})
	// contains filtered or unexported fields
}

func New

func New(devMode bool) (*Router, error)

New returns a pointer to a new Router

func (*Router) DELETE

func (r *Router) DELETE(pattern string, handler AuthHandler, authType AuthType) Route

DELETE is a shortcut for creating a new Route

func (*Router) GET

func (r *Router) GET(pattern string, handler AuthHandler, authType AuthType) Route

GET is a shortcut for creating a new Route

func (*Router) Handle

func (r *Router) Handle(httpMethod, pattern string, handler AuthHandler, authType AuthType) Route

Handle validates, creates, and appends a Route to the routes array

func (*Router) POST

func (r *Router) POST(pattern string, handler AuthHandler, authType AuthType) Route

POST is a shortcut for creating a new Route

func (*Router) PUT

func (r *Router) PUT(pattern string, handler AuthHandler, authType AuthType) Route

PUT is a shortcut for creating a new Route

func (*Router) PrintRoutes

func (r *Router) PrintRoutes()

PrintRoutes to display in the console/log

func (*Router) RegisterMiddleware

func (r *Router) RegisterMiddleware(handler http.HandlerFunc)

RegisterMiddleware takes a handle function and adds it to the array of middleware handlers

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(response http.ResponseWriter, request *http.Request)

ServeHTTP implements the http.handler interface

Jump to

Keyboard shortcuts

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