router

package
v0.0.0-...-34f8086 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App represents the core web application structure, managing routes, middlewares, and plugins.

func NewApp

func NewApp() *App

NewApp creates a new App instance with an initialized root node. Returns:

*App: A new App instance.

func (*App) AddPlugin

func (a *App) AddPlugin(p plugins.Plugin)

AddPlugin adds a plugin to the App's plugin stack. Args:

p (plugins.Plugin): The plugin to add.

func (*App) Connect

func (a *App) Connect(path string, handler req.Handler)

Connect registers a handler for the CONNECT HTTP method. Args:

path (string): The route path.
handler (req.Handler): The handler function.

func (*App) Delete

func (a *App) Delete(path string, handler req.Handler)

Delete registers a handler for the DELETE HTTP method. Args:

path (string): The route path.
handler (req.Handler): The handler function.

func (*App) Get

func (a *App) Get(path string, handler req.Handler)

Get registers a handler for the GET HTTP method. Args:

path (string): The route path.
handler (req.Handler): The handler function.

func (*App) Head

func (a *App) Head(path string, handler req.Handler)

Head registers a handler for the HEAD HTTP method. Args:

path (string): The route path.
handler (req.Handler): The handler function.

func (*App) Listen

func (a *App) Listen(addr string) error

Listen starts the HTTP server on the specified address and handles graceful shutdown. Args:

addr (string): The address to listen on (e.g., ":8080").

Returns:

error: An error if the server fails to start or shutdown.

func (*App) Options

func (a *App) Options(path string, handler req.Handler)

Options registers a handler for the OPTIONS HTTP method. Args:

path (string): The route path.
handler (req.Handler): The handler function.

func (*App) Patch

func (a *App) Patch(path string, handler req.Handler)

Patch registers a handler for the PATCH HTTP method. Args:

path (string): The route path.
handler (req.Handler): The handler function.

func (*App) Post

func (a *App) Post(path string, handler req.Handler)

Post registers a handler for the POST HTTP method. Args:

path (string): The route path.
handler (req.Handler): The handler function.

func (*App) Put

func (a *App) Put(path string, handler req.Handler)

Put registers a handler for the PUT HTTP method. Args:

path (string): The route path.
handler (req.Handler): The handler function.

func (*App) RegisterPlugins

func (a *App) RegisterPlugins()

RegisterPlugins registers all plugins added to the App.

func (*App) Route

func (a *App) Route(method, path string, handler req.Handler)

Route registers a route for a specific HTTP method and path. Args:

method (string): The HTTP method (e.g., "GET").
path (string): The route path.
handler (req.Handler): The handler function for the route.

func (*App) ServeHTTP

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles incoming HTTP requests and dispatches them to the appropriate route. Args:

w (http.ResponseWriter): The response writer.
r (*http.Request): The incoming request.

func (*App) Trace

func (a *App) Trace(path string, handler req.Handler)

Trace registers a handler for the TRACE HTTP method. Args:

path (string): The route path.
handler (req.Handler): The handler function.

func (*App) Use

func (a *App) Use(mw Middleware)

Use adds a middleware function to the App's middleware stack. Args:

mw (Middleware): The middleware function to add.

type Middleware

type Middleware func(http.HandlerFunc) http.HandlerFunc

Middleware defines a function signature for middleware.

type Node

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

func NewNode

func NewNode(segment string) *Node

func (*Node) AddRoute

func (n *Node) AddRoute(path []string, handler http.HandlerFunc)

func (*Node) FindRoute

func (n *Node) FindRoute(path []string) (http.HandlerFunc, bool)

type Route

type Route struct {
	Path    string
	Handler func(req *req.Request, res *req.Response)
}

func NewRoute

func NewRoute(path string, handler func(req *req.Request, res *req.Response)) *Route

Jump to

Keyboard shortcuts

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