libNetHttp

package
v2.0.0-...-51e8ac7 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package libNetHttp provides the v2 net/http web framework adapter for requestCore.

It embeds the v1 github.com/hmmftg/requestCore/libNetHttp.NetHTTPParser and adds raw response writing, cookie access, and v2 routing support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHTTPRequest

func GetHTTPRequest(ctx any) *http.Request

GetHTTPRequest extracts the *http.Request from a LegacyContext created by NetHTTPRouter. The LegacyContext is a context.Context carrying the request and response writer via libNetHttp.WithRequestResponse.

func GetHTTPResponseWriter

func GetHTTPResponseWriter(ctx any) http.ResponseWriter

GetHTTPResponseWriter extracts the http.ResponseWriter from a LegacyContext created by NetHTTPRouter.

Types

type NetHTTPParserV2

type NetHTTPParserV2 struct {
	*legacyLibNetHttp.NetHTTPParser
	// contains filtered or unexported fields
}

NetHTTPParserV2 extends the v1 NetHTTPParser with raw response writing and cookie access for v2 renderer and session support.

func InitContextV2

func InitContextV2(r *http.Request, w http.ResponseWriter) *NetHTTPParserV2

InitContextV2 creates a NetHTTPParserV2 from an HTTP request and response writer.

func (*NetHTTPParserV2) CheckURLParam

func (p *NetHTTPParserV2) CheckURLParam(name string) (string, bool)

CheckURLParam returns a URL path parameter and whether it exists.

func (*NetHTTPParserV2) GetCookie

func (p *NetHTTPParserV2) GetCookie(name string) string

GetCookie returns the value of the named request cookie.

func (*NetHTTPParserV2) GetURLParam

func (p *NetHTTPParserV2) GetURLParam(name string) string

GetURLParam returns a URL path parameter by name. It first checks the parser's Params map (populated by chi or manual setup), then falls back to Go 1.22+ ServeMux's req.PathValue().

func (*NetHTTPParserV2) SendResponse

func (p *NetHTTPParserV2) SendResponse(status int, contentType string, body []byte) error

SendResponse writes a raw response with the given status, content type, and body bytes to the HTTP response writer. If a CommitState is bound and already committed, returns nil without writing. Before writing, the before-commit hook runner is invoked (if set) so that session cookies and other pre-write side effects are persisted even for direct parser writes.

func (*NetHTTPParserV2) SetBeforeCommitHookRunner

func (p *NetHTTPParserV2) SetBeforeCommitHookRunner(fn func() error)

SetBeforeCommitHookRunner binds a function that runs before-commit hooks before SendResponse writes the response.

func (*NetHTTPParserV2) SetCommitState

func (p *NetHTTPParserV2) SetCommitState(cs *v2wf.CommitState)

SetCommitState binds the request's CommitState to this parser so that SendResponse can check and update the committed status.

func (*NetHTTPParserV2) SetCookie

func (p *NetHTTPParserV2) SetCookie(cookie *http.Cookie)

SetCookie sets an HTTP response cookie.

type NetHTTPRouter

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

NetHTTPRouter implements routing.Router for net/http using http.ServeMux. It is the base router for the net/http adapter. The chi adapter wraps this to provide richer routing features.

func NewRouter

func NewRouter() *NetHTTPRouter

NewRouter creates a new NetHTTPRouter with a new http.ServeMux.

func NewRouterFromMux

func NewRouterFromMux(mux *http.ServeMux) *NetHTTPRouter

NewRouterFromMux creates a new NetHTTPRouter from an existing http.ServeMux.

func (*NetHTTPRouter) Delete

func (r *NetHTTPRouter) Delete(pattern string, handler routing.Handler) error

Delete registers a DELETE handler.

func (*NetHTTPRouter) Get

func (r *NetHTTPRouter) Get(pattern string, handler routing.Handler) error

Get registers a GET handler.

func (*NetHTTPRouter) Group

func (r *NetHTTPRouter) Group(prefix string) routing.RouteGroup

Group creates a sub-group with the given prefix. net/http's ServeMux doesn't have native groups, so we prefix patterns.

func (*NetHTTPRouter) Handle

func (r *NetHTTPRouter) Handle(method, pattern string, handler routing.Handler) error

Handle registers a handler for the given method and pattern. Uses Go 1.22+ ServeMux pattern syntax: "METHOD /path".

func (*NetHTTPRouter) Head

func (r *NetHTTPRouter) Head(pattern string, handler routing.Handler) error

Head registers a HEAD handler.

func (*NetHTTPRouter) MethodNotAllowed

func (r *NetHTTPRouter) MethodNotAllowed(handler routing.Handler)

MethodNotAllowed sets the handler for disallowed methods. Go 1.22+ ServeMux handles 405 automatically by writing a 405 response. We wrap the mux to intercept 405 responses and route them through the v2 response handler/registry.

func (*NetHTTPRouter) Native

func (r *NetHTTPRouter) Native() any

Native returns the underlying http.ServeMux, wrapped with 405 interception if a MethodNotAllowed handler has been configured.

func (*NetHTTPRouter) NotFound

func (r *NetHTTPRouter) NotFound(handler routing.Handler)

NotFound sets the handler for unmatched routes.

func (*NetHTTPRouter) Patch

func (r *NetHTTPRouter) Patch(pattern string, handler routing.Handler) error

Patch registers a PATCH handler.

func (*NetHTTPRouter) Post

func (r *NetHTTPRouter) Post(pattern string, handler routing.Handler) error

Post registers a POST handler.

func (*NetHTTPRouter) Put

func (r *NetHTTPRouter) Put(pattern string, handler routing.Handler) error

Put registers a PUT handler.

func (*NetHTTPRouter) SetErrorHandler

func (r *NetHTTPRouter) SetErrorHandler(handler *response.Handler)

SetErrorHandler installs the v2 response handler and error registry used for centralized error dispatch.

func (*NetHTTPRouter) With

func (r *NetHTTPRouter) With(middleware ...routing.Middleware) routing.RouteGroup

With returns a new group with additional middleware.

Jump to

Keyboard shortcuts

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