kosha

package module
v0.0.0-...-17e08ff Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: MIT Imports: 8 Imported by: 0

README

Kosha

A modern, full-featured, and blazing-fast Go web framework built on net/http, with support for MVC, DI, WebSockets, and gRPC — inspired by Chi, Spring Boot, and Laravel.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	Request() *http.Request
	Response() http.ResponseWriter
}

func NewContext

func NewContext(w http.ResponseWriter, r *http.Request) Context

type HandlerFunc

type HandlerFunc func(ctx Context) error

type Middleware

type Middleware func(c Context, next HandlerFunc) error

Middleware defines a function that wraps a HandlerFunc. It receives the current Context and the next HandlerFunc in the chain.

type Params

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

Params holds the path parameters extracted from the HTTP request.

func (Params) ByName

func (p Params) ByName(name string) string

ByName returns the value of the first parameter that matched the given name. Otherwise, an empty string is returned.

func (Params) Count

func (p Params) Count() int

Count returns the number of parameters.

func (Params) Name

func (p Params) Name(i int) string

Name returns the parameter name of the given index.

func (Params) Value

func (p Params) Value(i int) string

Value returns the parameter value of ther given index.

type Pattern

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

func MustPattern

func MustPattern(p Pattern, err error) Pattern

MustPattern is a helper function which makes it easier to call NewPattern or NewGRPCPattern in variable initialization.

func NewPattern

func NewPattern(pattern string, regexps *[]*regexp.Regexp) (p Pattern, err error)

NewPattern creates a default style's new Pattern from the given original pattern. "regexps" is a list of regular expressions shared between multiple patterns.

The syntax of the pattern string is as follows:

Pattern		= "/" Segments
Segments	= Segment { "/" Segment }
Segment		= LITERAL | Parameter
Parameter	= Anonymous | Named
Anonymous	= ":" | "*"
Named		= ":" FieldPath [ "=" Regexp ] | "*" FieldPath
FieldPath	= IDENT { "." IDENT }

func (Pattern) Field

func (p Pattern) Field(i int) string

Field returns a pattern's i'th field name.

func (Pattern) Key

func (p Pattern) Key() string

Key returns the key value of the pattern.

func (Pattern) NumField

func (p Pattern) NumField() int

NumField returns a pattern's field count.

func (Pattern) Pattern

func (p Pattern) Pattern() string

Pattern returns the original pattern (example: /v1/users/:id)

type Route

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

Route represents a single route with support for HTTP method-based handlers and associated middleware.

func NewRoute

func NewRoute(parentMiddleware []Middleware) *Route

NewRoute creates and returns a new Route instance with an initialized handlers map and inherited middleware.

The parentMiddleware parameter represents middleware inherited from a parent group or router. These middlewares will be applied to all handlers registered on this Route unless overridden.

It performs a shallow copy of the parent middleware slice to avoid side effects from future modifications.

func (*Route) Add

func (r *Route) Add(method string, handler HandlerFunc, routeMiddleware ...Middleware) *Route

Add registers a handler for the specified HTTP method. It first applies any route-specific middleware followed by the route's global middleware.

It panics if a handler for the method already exists.

func (*Route) Connect

func (r *Route) Connect(handler HandlerFunc, routeMiddleware ...Middleware) *Route

Connect registers a handler for HTTP CONNECT requests.

func (*Route) Delete

func (r *Route) Delete(handler HandlerFunc, routeMiddleware ...Middleware) *Route

Delete registers a handler for HTTP DELETE requests.

func (*Route) Get

func (r *Route) Get(handler HandlerFunc, routeMiddleware ...Middleware) *Route

Get registers a handler for HTTP GET requests.

func (*Route) Head

func (r *Route) Head(handler HandlerFunc, routeMiddleware ...Middleware) *Route

Head registers a handler for HTTP HEAD requests.

func (*Route) Options

func (r *Route) Options(handler HandlerFunc, routeMiddleware ...Middleware) *Route

Options registers a handler for HTTP OPTIONS requests.

func (*Route) Patch

func (r *Route) Patch(handler HandlerFunc, routeMiddleware ...Middleware) *Route

Patch registers a handler for HTTP PATCH requests.

func (*Route) Post

func (r *Route) Post(handler HandlerFunc, routeMiddleware ...Middleware) *Route

Post registers a handler for HTTP POST requests.

func (*Route) Put

func (r *Route) Put(handler HandlerFunc, routeMiddleware ...Middleware) *Route

Put registers a handler for HTTP PUT requests.

func (*Route) Trace

func (r *Route) Trace(handler HandlerFunc, routeMiddleware ...Middleware) *Route

Trace registers a handler for HTTP TRACE requests.

type Router

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

Router is the core HTTP router that manages route registration and middleware. It allows defining routes for different HTTP methods, supports global middleware, and maps paths to route handlers.

func NewRouter

func NewRouter() *Router

NewRouter creates and returns a new Router instance with initialized routes map.

func (*Router) Add

func (r *Router) Add(method, path string, handler HandlerFunc, middleware ...Middleware) *Route

Add registers a route handler for the given HTTP method and path. It applies any global middleware and the route-specific middleware provided. Panics if a route with the same path already exists.

func (*Router) Connect

func (r *Router) Connect(path string, handler HandlerFunc, middleware ...Middleware) *Route

Connect registers a route that responds to HTTP CONNECT requests.

func (*Router) Delete

func (r *Router) Delete(path string, handler HandlerFunc, middleware ...Middleware) *Route

Delete registers a route that responds to HTTP DELETE requests.

func (*Router) Get

func (r *Router) Get(path string, handler HandlerFunc, middleware ...Middleware) *Route

Get registers a route that responds to HTTP GET requests.

func (*Router) Head

func (r *Router) Head(path string, handler HandlerFunc, middleware ...Middleware) *Route

Head registers a route that responds to HTTP HEAD requests.

func (*Router) Options

func (r *Router) Options(path string, handler HandlerFunc, middleware ...Middleware) *Route

Options registers a route that responds to HTTP OPTIONS requests.

func (*Router) Patch

func (r *Router) Patch(path string, handler HandlerFunc, middleware ...Middleware) *Route

Patch registers a route that responds to HTTP PATCH requests.

func (*Router) Post

func (r *Router) Post(path string, handler HandlerFunc, middleware ...Middleware) *Route

Post registers a route that responds to HTTP POST requests.

func (*Router) Put

func (r *Router) Put(path string, handler HandlerFunc, middleware ...Middleware) *Route

Put registers a route that responds to HTTP PUT requests.

func (*Router) Trace

func (r *Router) Trace(path string, handler HandlerFunc, middleware ...Middleware) *Route

Trace registers a route that responds to HTTP TRACE requests.

func (*Router) Use

func (r *Router) Use(mw ...Middleware)

Use adds global middleware to the router, which will be inherited by all routes.

Jump to

Keyboard shortcuts

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