web

package module
v0.0.0-...-db255c3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParsePattern

func ParsePattern(pattern string) []string

解析路径为[]string

Types

type Context

type Context struct {
	//origin objects
	Writer http.ResponseWriter
	Req    *http.Request
	//request info
	Path   string
	Method string
	Params map[string]string
	//response info
	StatusCode int
	//middlewares
	Middlewares []HandleFunc
	// contains filtered or unexported fields
}

上下文

func NewContext

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

Context构造函数

func (*Context) Data

func (context *Context) Data(code int, data []byte)

快速构造Data响应

func (*Context) Fail

func (context *Context) Fail(code int, err string)

错误

func (*Context) HTML

func (context *Context) HTML(code int, name string, data interface{})

快速构造HTML响应

func (*Context) JSON

func (context *Context) JSON(code int, obj interface{})

快速构造JSON响应

func (*Context) Next

func (context *Context) Next()

执行中间件

func (*Context) Param

func (context *Context) Param(key string) string

解析动态路由中key匹配值参数

func (*Context) PostForm

func (context *Context) PostForm(key string) string

提供访问PostForm参数方法

func (*Context) Query

func (context *Context) Query(key string) string

提供访问Query参数方法

func (*Context) SetHeader

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

设置响应头

func (*Context) Status

func (context *Context) Status(code int)

设置状态码

func (*Context) String

func (context *Context) String(code int, format string, values ...interface{})

快速构造String响应

type Engine

type Engine struct {
	*RouterGroup
	// contains filtered or unexported fields
}

Engine实现ServeHTTP的接口,添加路由映射表

func New

func New() *Engine

Engine构造函数

func (*Engine) AddRoute

func (engine *Engine) AddRoute(method string, pattern string, handler HandleFunc)

添加静态路由的方法

func (*Engine) GET

func (engine *Engine) GET(pattern string, handler HandleFunc)

添加GET请求的方法

func (*Engine) LoadHTMLGlob

func (engine *Engine) LoadHTMLGlob(pattern string)

func (*Engine) POST

func (engine *Engine) POST(pattern string, handler HandleFunc)

添加POST请求的方法

func (*Engine) Run

func (engine *Engine) Run(addr string) error

启动HTTP服务端的方法

func (*Engine) ServeHTTP

func (engine *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)

解析请求路径,查找路由映射表。如果查到就执行注册的方法,否则返回404

func (*Engine) SetFuncMap

func (engine *Engine) SetFuncMap(funcMap template.FuncMap)

type H

type H map[string]interface{}

type HandleFunc

type HandleFunc func(context *Context)

定义路由映射的处理方法

func Logger

func Logger() HandleFunc

日志中间件

func Recovery

func Recovery() HandleFunc

type Router

type Router struct {
	Handlers map[string]HandleFunc
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter() *Router

func (*Router) AddRoute

func (router *Router) AddRoute(method string, pattern string, handler HandleFunc)

添加路由

type RouterGroup

type RouterGroup struct {
	Middlewares []HandleFunc //中间件
	// contains filtered or unexported fields
}

路由分组

func (*RouterGroup) AddRoute

func (group *RouterGroup) AddRoute(method string, comp string, handler HandleFunc)

按组添加路由

func (*RouterGroup) CreateStaticHandler

func (group *RouterGroup) CreateStaticHandler(relativePath string, fs http.FileSystem) HandleFunc

创建静态文件服务

func (*RouterGroup) GET

func (group *RouterGroup) GET(comp string, handler HandleFunc)

按组添加GET路由

func (*RouterGroup) Group

func (group *RouterGroup) Group(prefix string) *RouterGroup

新建分组

func (*RouterGroup) POST

func (group *RouterGroup) POST(comp string, handler HandleFunc)

按组添加POST路由

func (*RouterGroup) Static

func (group *RouterGroup) Static(relativePath string, root string)

启动静态文件服务

func (*RouterGroup) Use

func (group *RouterGroup) Use(middlewares ...HandleFunc)

添加中间件

Jump to

Keyboard shortcuts

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