serve

package module
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 9 Imported by: 1

README

基于 http 的 Web 框架

提供基本的动态路由、中间件及模板解析系列功能。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Writer http.ResponseWriter
	Req    *http.Request

	// request
	Path   string
	Method string
	Params map[string]string
	// response
	StatusCode int
	// contains filtered or unexported fields
}

func (*Context) Data

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

func (*Context) Fail

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

func (*Context) HTML

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

func (*Context) JSON

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

func (*Context) Next

func (c *Context) Next()

func (*Context) Param

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

func (*Context) PostForm

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

func (*Context) Query

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

func (*Context) SetHeader

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

func (*Context) Status

func (c *Context) Status(code int)

func (*Context) String

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

type Engine

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

func Default

func Default() *Engine

func New

func New() *Engine

func (*Engine) LoadHTMLGlob

func (engine *Engine) LoadHTMLGlob(pattern string)

func (*Engine) ServeHTTP

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

func (*Engine) SetFuncMap

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

type H

type H map[string]interface{} // header json

type HandlerFunc

type HandlerFunc func(*Context)

func Logger

func Logger() HandlerFunc

func Recovery

func Recovery() HandlerFunc

type RouterGroup

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

func (*RouterGroup) GET

func (group *RouterGroup) GET(pattern string, handler HandlerFunc)

func (*RouterGroup) Group

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

func (*RouterGroup) POST

func (group *RouterGroup) POST(pattern string, handler HandlerFunc)

func (*RouterGroup) Run

func (group *RouterGroup) Run(addr string) error

func (*RouterGroup) Static

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

将某个本地目录,映射到路由 relativePath 上 一般是某些静态文件

func (*RouterGroup) Use

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

Jump to

Keyboard shortcuts

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