stdlib

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package stdlib 提供基于标准库 net/http 的引擎实现。

Package stdlib 提供基于标准库 net/http 的引擎实现。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

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

Context 标准库 HTTP 上下文实现。

func NewContext

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

NewContext 创建新的 HTTP 上下文。

func (*Context) AbortWithStatus

func (c *Context) AbortWithStatus(code int)

AbortWithStatus 中止请求。

func (*Context) AbortWithStatusJSON

func (c *Context) AbortWithStatusJSON(code int, body any)

AbortWithStatusJSON 中止请求并返回 JSON。

func (*Context) BindJSON

func (c *Context) BindJSON(target any) error

BindJSON 解析 JSON 请求体。

func (*Context) Context

func (c *Context) Context() context.Context

Context 获取请求上下文。

func (*Context) Header

func (c *Context) Header(key string) string

Header 获取请求头。

func (*Context) IsAborted

func (c *Context) IsAborted() bool

IsAborted 判断是否已中止。

func (*Context) JSON

func (c *Context) JSON(code int, data any) error

JSON 返回 JSON 响应。

func (*Context) Next

func (c *Context) Next()

Next 执行下一个中间件。

func (*Context) PathParam

func (c *Context) PathParam(name string) string

PathParam 获取路径参数。

func (*Context) Query

func (c *Context) Query(name string) string

Query 获取查询参数。

func (*Context) QueryDefault

func (c *Context) QueryDefault(name, defaultVal string) string

QueryDefault 获取查询参数(带默认值)。

func (*Context) Request added in v0.0.4

func (c *Context) Request() *http.Request

Request 获取底层 HTTP 请求。

func (*Context) RequestMethod

func (c *Context) RequestMethod() string

RequestMethod 返回请求方法。

func (*Context) RequestURI

func (c *Context) RequestURI() string

RequestURI 返回请求 URI。

func (*Context) SetContext

func (c *Context) SetContext(ctx context.Context)

SetContext 设置请求上下文。

func (*Context) SetHeader

func (c *Context) SetHeader(key, value string)

SetHeader 设置响应头。

func (*Context) SetStatusCode

func (c *Context) SetStatusCode(code int)

SetStatusCode 设置响应状态码。

func (*Context) String

func (c *Context) String(code int, format string, args ...any)

String 返回字符串响应。

func (*Context) WithMiddleware

func (c *Context) WithMiddleware(mw []core.MiddlewareFunc, handler core.HandlerFunc) *Context

WithMiddleware 设置中间件链。

func (*Context) WithParams

func (c *Context) WithParams(params map[string]string) *Context

WithParams 设置路径参数。

type Factory

type Factory struct{}

Factory 标准库引擎工厂。

func (*Factory) CreateRouter

func (f *Factory) CreateRouter() (core.Router, error)

CreateRouter 创建路由器。

func (*Factory) CreateServer

func (f *Factory) CreateServer(opts ...engine.ServerOption) (core.Server, error)

CreateServer 创建服务器。

func (*Factory) Type

func (f *Factory) Type() engine.Type

Type 返回引擎类型。

type Router

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

Router 标准库路由器实现。

func NewRouter

func NewRouter() *Router

NewRouter 创建新的路由器。

func (*Router) DELETE

func (r *Router) DELETE(path string, handler core.HandlerFunc)

DELETE 注册 DELETE 路由。

func (*Router) GET

func (r *Router) GET(path string, handler core.HandlerFunc)

GET 注册 GET 路由。

func (*Router) Group

func (r *Router) Group(prefix string) core.Router

Group 创建路由组。

func (*Router) PATCH

func (r *Router) PATCH(path string, handler core.HandlerFunc)

PATCH 注册 PATCH 路由。

func (*Router) POST

func (r *Router) POST(path string, handler core.HandlerFunc)

POST 注册 POST 路由。

func (*Router) PUT

func (r *Router) PUT(path string, handler core.HandlerFunc)

PUT 注册 PUT 路由。

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP 实现 http.Handler 接口。

func (*Router) Use

func (r *Router) Use(middleware core.MiddlewareFunc)

Use 注册中间件。

type Server

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

Server 标准库服务器实现。

func NewServer

func NewServer(opts ...engine.ServerOption) *Server

NewServer 创建新的 HTTP 服务器。

func (*Server) SetHandler

func (s *Server) SetHandler(handler any)

SetHandler 设置处理器。

func (*Server) Start

func (s *Server) Start() error

Start 启动 HTTP 服务器。

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop 优雅地停止服务器。

func (*Server) Use

func (s *Server) Use(m any)

Use 注册中间件。

Jump to

Keyboard shortcuts

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