yun

package module
v0.0.0-...-76dd719 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2016 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MIMEApplicationJSON                  = "application/json"
	MIMEApplicationJSONCharsetUTF8       = MIMEApplicationJSON + "; " + charsetUTF8
	MIMEApplicationJavaScript            = "application/javascript"
	MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8
	MIMEApplicationXML                   = "application/xml"
	MIMEApplicationXMLCharsetUTF8        = MIMEApplicationXML + "; " + charsetUTF8
	MIMEApplicationForm                  = "application/x-www-form-urlencoded"
	MIMEApplicationProtobuf              = "application/protobuf"
	MIMEApplicationMsgpack               = "application/msgpack"
	MIMETextHTML                         = "text/html"
	MIMETextHTMLCharsetUTF8              = MIMETextHTML + "; " + charsetUTF8
	MIMETextPlain                        = "text/plain"
	MIMETextPlainCharsetUTF8             = MIMETextPlain + "; " + charsetUTF8
	MIMEMultipartForm                    = "multipart/form-data"
	MIMEOctetStream                      = "application/octet-stream"
)

MIME types

View Source
const (
	HeaderAcceptEncoding                = "Accept-Encoding"
	HeaderAllow                         = "Allow"
	HeaderAuthorization                 = "Authorization"
	HeaderContentDisposition            = "Content-Disposition"
	HeaderContentEncoding               = "Content-Encoding"
	HeaderContentLength                 = "Content-Length"
	HeaderContentType                   = "Content-Type"
	HeaderCookie                        = "Cookie"
	HeaderSetCookie                     = "Set-Cookie"
	HeaderIfModifiedSince               = "If-Modified-Since"
	HeaderLastModified                  = "Last-Modified"
	HeaderLocation                      = "Location"
	HeaderUpgrade                       = "Upgrade"
	HeaderVary                          = "Vary"
	HeaderWWWAuthenticate               = "WWW-Authenticate"
	HeaderXForwardedProto               = "X-Forwarded-Proto"
	HeaderXHTTPMethodOverride           = "X-HTTP-Method-Override"
	HeaderXForwardedFor                 = "X-Forwarded-For"
	HeaderXRealIP                       = "X-Real-IP"
	HeaderServer                        = "Server"
	HeaderOrigin                        = "Origin"
	HeaderAccessControlRequestMethod    = "Access-Control-Request-Method"
	HeaderAccessControlRequestHeaders   = "Access-Control-Request-Headers"
	HeaderAccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	HeaderAccessControlAllowMethods     = "Access-Control-Allow-Methods"
	HeaderAccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	HeaderAccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	HeaderAccessControlMaxAge           = "Access-Control-Max-Age"

	// Security
	HeaderStrictTransportSecurity = "Strict-Transport-Security"
	HeaderXContentTypeOptions     = "X-Content-Type-Options"
	HeaderXXSSProtection          = "X-XSS-Protection"
	HeaderXFrameOptions           = "X-Frame-Options"
	HeaderContentSecurityPolicy   = "Content-Security-Policy"
	HeaderXCSRFToken              = "X-CSRF-Token"
)

Headers

View Source
const (
	CONNECT = "CONNECT"
	DELETE  = "DELETE"
	GET     = "GET"
	HEAD    = "HEAD"
	OPTIONS = "OPTIONS"
	PATCH   = "PATCH"
	POST    = "POST"
	PUT     = "PUT"
	TRACE   = "TRACE"
)

HTTP methods

Variables

This section is empty.

Functions

func ContentTypeByExtension

func ContentTypeByExtension(name string) (t string)

ContentTypeByExtension ...

Types

type Context

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

Context 请求、响应上下文

func (*Context) Abort

func (c *Context) Abort()

Abort 中止响应

func (*Context) AbortCode

func (c *Context) AbortCode(code int)

AbortCode 以指定响应状态码中止响应 code 响应状态码

func (*Context) Attachment

func (c *Context) Attachment(r io.ReadSeeker, name string) (err error)

Attachment 响应附件 r 文件读取接口 name 文件名 return 返回错误

func (*Context) Body

func (c *Context) Body() ([]byte, error)

Body 获取响应体 return 响应内容的二进制数组、错误

func (*Context) BytesToString

func (c *Context) BytesToString(b []byte) string

BytesToString 将二进制数组转换成字符串 b 二进制数组 return 返回字符串

func (*Context) DecodeJSON

func (c *Context) DecodeJSON(obj interface{}) error

DecodeJSON 将响应体解析成对象 obj 转换结果 return 返回错误

func (*Context) File

func (c *Context) File(file string)

File 文件服务器 file 文件的路径

func (*Context) Form

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

Form 获取字符串类型的非必须参数 key 参数名称 retrun 返回字符串值

func (*Context) FormInt

func (c *Context) FormInt(key string, defValue int) int

FormInt 获取int类型的非必须参数

func (*Context) Get

func (c *Context) Get(key string) (value interface{}, exists bool)

Get 获取中间件 key 键值 return 返回中间件对象与是否取得成功标志

func (*Context) HTML

func (c *Context) HTML(code int, html string) (err error)

HTML 响应为HTML code 响应状态码 html html字符串 return 返回错误

func (*Context) IsAborted

func (c *Context) IsAborted() bool

IsAborted 响应是否被中止 return

func (*Context) JSON

func (c *Context) JSON(code int, i interface{}) (err error)

JSON 响应为JSON code 响应状态码 i 将要转换为JSON的对象 return 返回错误

func (*Context) JSONBlob

func (c *Context) JSONBlob(code int, b []byte) (err error)

JSONBlob ...

func (*Context) JSONP

func (c *Context) JSONP(code int, callback string, i interface{}) (err error)

JSONP ...

func (*Context) MustForm

func (c *Context) MustForm(key string) (string, error)

MustForm 获取字符串类型的参数 key 参数名称 return 返回字符串、错误

func (*Context) MustFormInt

func (c *Context) MustFormInt(key string) (int, error)

MustFormInt 获取int类型的参数

func (*Context) Next

func (c *Context) Next()

Next 执行下一handle

func (*Context) NoContent

func (c *Context) NoContent(code int) error

NoContent 无内容响应 code 响应状态码 return 返回错误

func (*Context) Request

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

Request 获取请求

func (*Context) Response

func (c *Context) Response() http.ResponseWriter

Response 获取响应

func (*Context) Send

func (c *Context) Send(method, url string, body []byte) ([]byte, int, error)

Send 发送请求 method 请求方法 url 请求的地址 body 请求体 return 返回响应体、响应状态码、错误

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set 保存中间件 key 键值 value 中间件对象

func (*Context) String

func (c *Context) String(code int, s string) (err error)

String 响应为字符串 code 响应状态码 s 字符串 return 返回错误

func (*Context) StringToBytes

func (c *Context) StringToBytes(s string) []byte

StringToBytes 将字符串转换成二进制数组 s 将要被转换的字符串 return 返回二进制数组

func (*Context) XML

func (c *Context) XML(code int, i interface{}) (err error)

XML 响应为XML code 响应状态码 i 将要转换成XML的对象 return 返回错误

func (*Context) XMLBlob

func (c *Context) XMLBlob(code int, b []byte) (err error)

XMLBlob ...

type Engine

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

Engine 框架引擎

func New

func New(mode Mode) *Engine

New 新建框架引擎 mode 运行模式,可选DEBUG,TEST,RELEASE return 返回框架引擎

func (*Engine) Group

func (eng *Engine) Group(path string, middles ...HandlerFunc) *Group

Group 创建路由组 path 路由组路径 middles 中间件 return 路由组对象

func (*Engine) Handle

func (eng *Engine) Handle(path string) IRoute

Handle 路由 path 路由路径 return 路由接口

func (*Engine) IsDebugging

func (eng *Engine) IsDebugging() bool

IsDebugging 是否调试模式

func (*Engine) Middlewares

func (eng *Engine) Middlewares() []HandlerFunc

Middlewares 获取中间件 return 中间件handles

func (*Engine) Run

func (eng *Engine) Run(addr ...string) error

Run 运行http服务 addr 服务地址 return 返回错误

func (*Engine) ServeHTTP

func (eng *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Engine) SetMode

func (eng *Engine) SetMode(mode Mode)

SetMode 设置运行模式 mode 运行模式,可选DEBUG,TEST,RELEASE

func (*Engine) Up

func (eng *Engine) Up() IGroup

Up 获取上层路由组 return 路由组接口

func (*Engine) Use

func (eng *Engine) Use(middleware ...HandlerFunc)

Use 加入中间件 middleware 中间件handle

type Group

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

Group 路由数组

func (*Group) Group

func (g *Group) Group(path string, middles ...HandlerFunc) *Group

Group 创建子路由组 path 组路径 middles 组中件间 return 返回路由组

func (*Group) Handle

func (g *Group) Handle(rpath string) IRoute

Handle 组路由路径 rpath 路径字符串 return 路由接口

func (*Group) Middlewares

func (g *Group) Middlewares() []HandlerFunc

Middlewares 获取组路由中间件 return 中间件执行体

func (*Group) Up

func (g *Group) Up() IGroup

Up 获取上级路由组 return 路由组接口

func (*Group) Use

func (g *Group) Use(middles ...HandlerFunc)

Use 注册中间件 middles 中间件handle

type HandlerFunc

type HandlerFunc func(*Context)

HandlerFunc ...

type Handlers

type Handlers []HandlerFunc

Handlers handler数组

type IGroup

type IGroup interface {
	Use(...HandlerFunc)
	Handle(string) IRoute
	Group(string, ...HandlerFunc) *Group
	Middlewares() []HandlerFunc
	Up() IGroup
}

IGroup 路由组接口

type ILogger

type ILogger interface {
	SetOutput(io.Writer)
	Print(...interface{})
	Printf(string, ...interface{})
	Debug(...interface{})
	Debugf(string, ...interface{})
	Info(...interface{})
	Infof(string, ...interface{})
	Warn(...interface{})
	Warnf(string, ...interface{})
	Error(...interface{})
	Errorf(string, ...interface{})
	Fatal(...interface{})
	Fatalf(string, ...interface{})
}

ILogger 日志记录器接口

type IRoute

type IRoute interface {
	Connect(...HandlerFunc) IRoute
	Delete(...HandlerFunc) IRoute
	Get(...HandlerFunc) IRoute
	Head(...HandlerFunc) IRoute
	Options(...HandlerFunc) IRoute
	Patch(...HandlerFunc) IRoute
	Post(...HandlerFunc) IRoute
	Put(...HandlerFunc) IRoute
	Trace(...HandlerFunc) IRoute
	Any(...HandlerFunc)
}

IRoute 路由接口

type Mode

type Mode int

Mode 运行模式

const (
	//DEBUG 调试模式
	DEBUG Mode = iota
	//TEST 测试模式
	TEST
	//RELEASE 发行模式
	RELEASE
)

type Param

type Param struct {
	Key   string
	Value string
}

Param 参数路由的参数

type Params

type Params []Param

Params 参数数组

func (Params) Get

func (ps Params) Get(name string) (string, error)

Get 获取参数值 name 参数名称 return 字符串类型的参数值或错误

func (Params) GetInt

func (ps Params) GetInt(name string) (int, error)

GetInt 获取整数型参数值 name 参数名称 return 整型值或错误

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Hijacker
	http.Flusher
	http.CloseNotifier

	//获取当前请求的响应状态码
	Status() int

	// 返回已写入HTTP响应体的字节数
	Size() int

	// 如果响应正文已被写入,则返回True
	Written() bool
}

ResponseWriter 响应写接口

Jump to

Keyboard shortcuts

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