router

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Make

func Make[T any](c *Context) (T, error)

Make 从容器解析服务(泛型版本)

Types

type Context

type Context struct {
	*gin.Context
	// contains filtered or unexported fields
}

Context 请求上下文

func (*Context) Abort

func (c *Context) Abort()

Abort 中止请求

func (*Context) AbortWithJSON

func (c *Context) AbortWithJSON(code int, obj any)

AbortWithJSON 中止请求并返回 JSON

func (*Context) AbortWithStatus

func (c *Context) AbortWithStatus(code int)

AbortWithStatus 中止请求并返回状态码

func (*Context) Error

func (c *Context) Error(message string)

Error 返回错误响应

func (*Context) ErrorWithCode

func (c *Context) ErrorWithCode(code int, message string)

ErrorWithCode 返回带错误码的错误响应

func (*Context) File

func (c *Context) File(name string) (*multipart.FileHeader, error)

File 获取上传文件

func (*Context) HTML

func (c *Context) HTML(code int, name string, obj any)

HTML 返回 HTML 响应

func (*Context) Input

func (c *Context) Input(key string, defaultValue ...string) string

Input 获取输入参数

func (*Context) InputBool

func (c *Context) InputBool(key string, defaultValue ...bool) bool

InputBool 获取布尔输入

func (*Context) InputInt

func (c *Context) InputInt(key string, defaultValue ...int) int

InputInt 获取整数输入

func (*Context) IsAborted

func (c *Context) IsAborted() bool

IsAborted 检查请求是否已中止

func (*Context) JSON

func (c *Context) JSON(code int, obj any)

JSON 返回 JSON 响应

func (*Context) Redirect

func (c *Context) Redirect(code int, location string)

Redirect 重定向

func (*Context) SaveFile

func (c *Context) SaveFile(name, dst string) error

SaveFile 保存上传文件

func (*Context) SetUser

func (c *Context) SetUser(user any)

SetUser 设置认证用户

func (*Context) String

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

String 返回字符串响应

func (*Context) Success

func (c *Context) Success(data any)

Success 返回成功响应

func (*Context) User

func (c *Context) User() (any, bool)

User 获取认证用户(需要配合认证中间件使用)

func (*Context) Validate

func (c *Context) Validate(obj any) error

Validate 验证请求数据

type HandlerFunc

type HandlerFunc func(*Context)

HandlerFunc 路由处理函数

type Middleware

type Middleware func(*Context) bool

Middleware 中间件函数

type Route

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

Route 路由

func (*Route) Middleware

func (r *Route) Middleware(middleware ...HandlerFunc) *Route

Middleware 为路由添加中间件

func (*Route) Name

func (r *Route) Name(name string) *Route

Name 设置路由名称

type Router

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

Router Laravel 风格的路由器

func New

func New(c *container.Container) *Router

New 创建新的路由器

func (*Router) Any

func (r *Router) Any(path string, handler HandlerFunc) *Route

Any 注册所有方法的路由

func (*Router) Delete

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

Delete 注册 DELETE 路由

func (*Router) Engine

func (r *Router) Engine() *gin.Engine

Engine 获取 Gin 引擎

func (*Router) Get

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

Get 注册 GET 路由

func (*Router) Group

func (r *Router) Group(prefix string, callback func(*Router)) *Router

Group 创建路由分组

func (*Router) Middleware

func (r *Router) Middleware(middleware ...HandlerFunc) *Router

Middleware 添加中间件

func (*Router) Options

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

Options 注册 OPTIONS 路由

func (*Router) Patch

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

Patch 注册 PATCH 路由

func (*Router) Post

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

Post 注册 POST 路由

func (*Router) Put

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

Put 注册 PUT 路由

func (*Router) Run

func (r *Router) Run(addr ...string) error

Run 启动服务器

func (*Router) SetMode

func (r *Router) SetMode(mode string)

SetMode 设置运行模式

Jump to

Keyboard shortcuts

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