gottp

package
v0.0.0-...-fe11d09 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitSession

func InitSession(cookieName string, cache *cache.Manager)

InitSession 初始化 要使用 Session 功能必须在程序初始化时调用此函数

Types

type Context

type Context struct {
	Writer  http.ResponseWriter
	Request *http.Request
	// contains filtered or unexported fields
}

Context http 请求信息定义

func (*Context) DecodeRequestBodyAsJSON

func (o *Context) DecodeRequestBodyAsJSON(v interface{}) error

DecodeRequestBodyAsJSON 把请求内容解析为 json

func (*Context) GetSeesion

func (o *Context) GetSeesion() cache.Entity

GetSeesion 获取 session 使用 session 的话,需要在 main 包中初始化 例:

cache := cache.NewCacheManager(memcache.PROVIDER, 600)
session.InitSeesion("go-session", cache)

func (*Context) NamedParamInURL

func (o *Context) NamedParamInURL(name string) string

NamedParamInURL 获取 url 中命名的参数,参见 httprouter 的参数名称 例如: /getinfo/:user

获取 :user 位置的参数,可使用此函数
	NamedParamInURL('user')

func (*Context) ParamInForm

func (o *Context) ParamInForm(name string) string

ParamInForm 获取 form 中提交的参数

func (*Context) ParamInURL

func (o *Context) ParamInURL(name string) string

ParamInURL 获取 url 中名称为 name 的第一个参数的值 注意是 ? 之后的 name=value 形式的参数

func (*Context) ResponseHeaderAdd

func (o *Context) ResponseHeaderAdd(key, value string)

ResponseHeaderAdd 追加返回头

func (*Context) ResponseHeaderSet

func (o *Context) ResponseHeaderSet(key, value string)

ResponseHeaderSet 设置返回头

func (*Context) ResponseJSON

func (o *Context) ResponseJSON(jsonObject interface{})

ResponseJSON 返回 json 数据

func (*Context) ResponseJSONStatus

func (o *Context) ResponseJSONStatus(status int, jsonObject interface{})

ResponseJSONStatus 返回 JSON 对象 注意:如果该函数执行成功,则会跳过排在该函数后面的代码

func (*Context) ResponseJSONSuccess

func (o *Context) ResponseJSONSuccess()

ResponseJSONSuccess 返回成功,内容为空

func (*Context) ResponseText

func (o *Context) ResponseText(text string)

ResponseText 返回文本

func (*Context) ResponseTextStatus

func (o *Context) ResponseTextStatus(status int, text string)

ResponseTextStatus 返回数据并指定状态

func (*Context) ResponseTextSuccess

func (o *Context) ResponseTextSuccess()

ResponseTextSuccess 返回成功,内容为空

func (*Context) ResponseTextf

func (o *Context) ResponseTextf(status int, formatter string, a ...interface{})

ResponseTextf 返回 string

func (*Context) ReturnFile

func (o *Context) ReturnFile(filePath string)

ReturnFile 返回文件,执行该函数不会跳过后面的代码

type Handler

type Handler func(context *Context)

Handler web服务函数定义

type Intercptor

type Intercptor func(path string, ctx *Context)

Intercptor 拦截器定义 如果要不执行后续操作,直接调用 ctx.Return* 函数

type JumpoutError

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

JumpoutError 跳过后续代码用到的错误定义

func (*JumpoutError) Error

func (e *JumpoutError) Error() string

type Manager

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

Manager 会话对象

var SSManager *Manager

SSManager 全局变量

func (*Manager) GenerateSID

func (ss *Manager) GenerateSID() string

GenerateSID 产生唯一的Session ID

func (*Manager) SessionDestory

func (ss *Manager) SessionDestory(w http.ResponseWriter, r *http.Request)

SessionDestory 注销Session

func (*Manager) SessionStart

func (ss *Manager) SessionStart(w http.ResponseWriter, r *http.Request) cache.Entity

SessionStart 启动Session功能

type PanicHandler

type PanicHandler func(path string, context *Context, err interface{}) bool

PanicHandler 错误处理函数定义 return bool

true	错误已经被处理,不再抛出
false	错误未被处理,抛出

type Router

type Router struct {
	Debug func(messsage string)
	Error func(err error)
	// contains filtered or unexported fields
}

Router 路由定义 对 httprouter.Router 包装

func NewRouter

func NewRouter() *Router

NewRouter 创建新的路由

func (*Router) AddAfterInterceptor

func (rc *Router) AddAfterInterceptor(interceptor Intercptor)

AddAfterInterceptor 添加执行后拦截器, 请勿在 AfterInterceptor 函数中调用 ctx.ResponseHeaderSet 和 ctx.ResponseHeaderAdd 函数

func (*Router) AddBeforeInterceptor

func (rc *Router) AddBeforeInterceptor(interceptor Intercptor)

AddBeforeInterceptor 添加执行前拦截器

func (*Router) AddPanicHandler

func (rc *Router) AddPanicHandler(handler PanicHandler)

AddPanicHandler 添加错误处理函数

func (*Router) DELETE

func (rc *Router) DELETE(path string, handler Handler)

DELETE 注册 DELETE 请求

func (*Router) GET

func (rc *Router) GET(path string, handler Handler)

GET 注册 GET 请求

func (*Router) GetHTTPRouter

func (rc *Router) GetHTTPRouter() *httprouter.Router

GetHTTPRouter 获取 http handler

func (*Router) HEAD

func (rc *Router) HEAD(path string, handler Handler)

HEAD 注册 HEAD 请求

func (*Router) POST

func (rc *Router) POST(path string, handler Handler)

POST 注册 POST 请求

func (*Router) PUT

func (rc *Router) PUT(path string, handler Handler)

PUT 注册 PUT 请求

Jump to

Keyboard shortcuts

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