web

package
v0.0.0-...-8ee38c3 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2018 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package web 使用net.http来封装gnet 不需要封装客户端

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPConn

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

HTTPConn 使用请求来模拟Conn

func NewHTTPConn

func NewHTTPConn(w http.ResponseWriter, r *http.Request, closeChan chan bool) *HTTPConn

NewHTTPConn 返回可用的Conn

func (*HTTPConn) Close

func (conn *HTTPConn) Close(ch gnet.Channel) (e error)

Close 关闭链接

func (*HTTPConn) Read

func (conn *HTTPConn) Read(ch gnet.Channel) (interface{}, error)

func (*HTTPConn) Request

func (conn *HTTPConn) Request() *http.Request

Request 返回底层对象

func (*HTTPConn) Response

func (conn *HTTPConn) Response() http.ResponseWriter

Response 返回底层对象

func (*HTTPConn) Write

func (conn *HTTPConn) Write(ch gnet.Channel, data interface{}) error

todo 要测试下多次写入

type HTTPContext

type HTTPContext interface {
	Request() *http.Request
	Container() ginjector.Container
	ReplaceContainer(ginjector.Container)
	Clear(interface{})
	Response() *HTTPResponseWriter
}

HTTPContext 中间件读取到的数据

type HTTPContextHandler

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

HTTPContextHandler 一个pipeline 可以多链接共享

func NewHTTPContextHandler

func NewHTTPContextHandler(container ginjector.Container) *HTTPContextHandler

NewHTTPContextHandler HTTPContextHandler

func (*HTTPContextHandler) Offline

func (handler *HTTPContextHandler) Offline(ctx *gnet.ChannelHandlerContext)

Offline 客户端断开链接 一定再调用Close之后触发

func (*HTTPContextHandler) Online

func (handler *HTTPContextHandler) Online(ctx *gnet.ChannelHandlerContext)

Online 在线

func (*HTTPContextHandler) Read

func (handler *HTTPContextHandler) Read(ctx *gnet.ChannelHandlerContext, last interface{})

func (*HTTPContextHandler) Write

func (handler *HTTPContextHandler) Write(ctx *gnet.ChannelHandlerContext, last interface{})

write前依次调用

type HTTPHandlerActionResult

type HTTPHandlerActionResult struct {
	Status int
	Data   interface{}
}

HTTPHandlerActionResult 函数可以返回HTTPHandlerActionResult 也可以不返回

type HTTPHandlerResponseMessage

type HTTPHandlerResponseMessage interface {
	Status() int
	Data() interface{}
}

HTTPHandlerResponseMessage 任何action最终都要返回这个结果

type HTTPLogHandler

type HTTPLogHandler struct {
}

HTTPLogHandler http协议的LOG模块 可多链接共享

func NewHTTPLogHandler

func NewHTTPLogHandler() *HTTPLogHandler

NewHTTPLogHandler 返回可用的LOG

func (*HTTPLogHandler) Offline

func (handler *HTTPLogHandler) Offline(ctx *gnet.ChannelHandlerContext)

Offline 客户端断开链接 一定再调用Close之后触发

func (*HTTPLogHandler) Online

func (handler *HTTPLogHandler) Online(ctx *gnet.ChannelHandlerContext)

Online 在线

func (*HTTPLogHandler) Read

func (handler *HTTPLogHandler) Read(ctx *gnet.ChannelHandlerContext, last interface{})

func (*HTTPLogHandler) Write

func (handler *HTTPLogHandler) Write(ctx *gnet.ChannelHandlerContext, last interface{})

write前依次调用

type HTTPParseHandler

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

HTTPParseHandler 解析http body

func NewHTTPParseHandler

func NewHTTPParseHandler() *HTTPParseHandler

NewHTTPParseHandler 返回HTTPParseHandler

func (*HTTPParseHandler) Adapte

func (handler *HTTPParseHandler) Adapte(key string, do ParseDo)

Adapte 添加对指定Content的转换器

func (*HTTPParseHandler) Offline

func (handler *HTTPParseHandler) Offline(ctx *gnet.ChannelHandlerContext)

Offline 客户端断开链接 一定再调用Close之后触发

func (*HTTPParseHandler) Online

func (handler *HTTPParseHandler) Online(ctx *gnet.ChannelHandlerContext)

Online 在线

func (*HTTPParseHandler) Read

func (handler *HTTPParseHandler) Read(ctx *gnet.ChannelHandlerContext, last interface{})

Invoke 中间件实现

func (*HTTPParseHandler) Write

func (handler *HTTPParseHandler) Write(ctx *gnet.ChannelHandlerContext, last interface{})

write前依次调用

type HTTPResponse

type HTTPResponse struct {
	Status int
	Data   []byte //string 或者真实的数据
}

HTTPResponse http的Response消息

type HTTPResponseWriter

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

HTTPResponseWriter 对http.ResponseWriter的包装 记录关键的属性 方便其他中间件使用

func (*HTTPResponseWriter) Header

func (rw *HTTPResponseWriter) Header() http.Header

Header http.ResponseWriter的实现

func (*HTTPResponseWriter) Hijack

func (rw *HTTPResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack implement http.Hijack

func (*HTTPResponseWriter) Size

func (rw *HTTPResponseWriter) Size() int

Size ret size

func (*HTTPResponseWriter) Status

func (rw *HTTPResponseWriter) Status() int

Status httpStatus

func (*HTTPResponseWriter) Write

func (rw *HTTPResponseWriter) Write(b []byte) (int, error)

Write http.ResponseWriter的实现

func (*HTTPResponseWriter) WriteHeader

func (rw *HTTPResponseWriter) WriteHeader(s int)

WriteHeader http.ResponseWriter的实现

func (*HTTPResponseWriter) WriteResult

func (rw *HTTPResponseWriter) WriteResult(s int, b []byte) (int, error)

WriteResult 方便一次性写响应体

func (*HTTPResponseWriter) Written

func (rw *HTTPResponseWriter) Written() bool

Written 是否已经写入

type HTTPResquest

type HTTPResquest struct {
	Req *http.Request
	Rsp *HTTPResponseWriter //必须暴露给外面 因为可能需要多header进行修改
}

HTTPResquest Request对象

type HTTPRouteHandler

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

HTTPRouteHandler http协议的Route模块 可多链接共享 目前只有精确匹配

func NewHTTPRouteHandler

func NewHTTPRouteHandler() *HTTPRouteHandler

NewHTTPRouteHandler 返回http route

func (*HTTPRouteHandler) AddRoute

func (handler *HTTPRouteHandler) AddRoute(method string, pattern string, f interface{}) *HTTPRouteHandler

AddRoute 添加路由映射

func (*HTTPRouteHandler) Any

func (handler *HTTPRouteHandler) Any(pattern string, f interface{}) *HTTPRouteHandler

Any 增加Any路由映射

func (*HTTPRouteHandler) Get

func (handler *HTTPRouteHandler) Get(pattern string, f interface{}) *HTTPRouteHandler

Get 增加GET路由映射 route的添加最好是预先添加后再加入pipeline 暂不支持动态添加

func (*HTTPRouteHandler) Offline

func (handler *HTTPRouteHandler) Offline(ctx *gnet.ChannelHandlerContext)

Offline 客户端断开链接 一定再调用Close之后触发

func (*HTTPRouteHandler) Online

func (handler *HTTPRouteHandler) Online(ctx *gnet.ChannelHandlerContext)

Online 在线

func (*HTTPRouteHandler) Post

func (handler *HTTPRouteHandler) Post(pattern string, f interface{}) *HTTPRouteHandler

Post 增加POST路由映射

func (*HTTPRouteHandler) Read

func (handler *HTTPRouteHandler) Read(ctx *gnet.ChannelHandlerContext, last interface{})

func (*HTTPRouteHandler) Write

func (handler *HTTPRouteHandler) Write(ctx *gnet.ChannelHandlerContext, last interface{})

write前依次调用

type HTTPServer

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

HTTPServer 使用http协议的Server

func NewHTTPServer

func NewHTTPServer(certFile, keyFile string) *HTTPServer

NewHTTPServer 返回HTTP的Server

func (*HTTPServer) ChannelConn

func (server *HTTPServer) ChannelConn() chan<- gnet.ChannelConn

ChannelConn start后有效

func (*HTTPServer) Close

func (server *HTTPServer) Close(bs *gnet.Bootstrap) error

Close 关闭服务端

func (*HTTPServer) Start

func (server *HTTPServer) Start(bs *gnet.Bootstrap) error

Start 启动Server

type HTTPValidateHandler

type HTTPValidateHandler struct {
}

HTTPValidateHandler 中间件 如果通过验证则会调用action

func NewHTTPValidateHandler

func NewHTTPValidateHandler() *HTTPValidateHandler

NewHTTPValidateHandler 返回中间件

func (*HTTPValidateHandler) Offline

func (handler *HTTPValidateHandler) Offline(ctx *gnet.ChannelHandlerContext)

Offline 客户端断开链接 一定再调用Close之后触发

func (*HTTPValidateHandler) Online

func (handler *HTTPValidateHandler) Online(ctx *gnet.ChannelHandlerContext)

Online 在线

func (*HTTPValidateHandler) Read

func (handler *HTTPValidateHandler) Read(ctx *gnet.ChannelHandlerContext, last interface{})

Read 中间件实现

func (*HTTPValidateHandler) Write

func (handler *HTTPValidateHandler) Write(ctx *gnet.ChannelHandlerContext, last interface{})

write前依次调用

type ParseDo

type ParseDo func(ctx HTTPContext) []reflect.Value

ParseDo 获得一个Content

type RouteHandler

type RouteHandler func(ctx HTTPContext)

RouteHandler 通用的Handler

type WSConn

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

WSConn 添加到Pipeline后 读写WebSocket

func NewWSConn

func NewWSConn(conn *websocket.Conn) *WSConn

NewWSConn 返回1个Conn

func (*WSConn) Close

func (conn *WSConn) Close(ch gnet.Channel) error

Close 关闭

func (*WSConn) Conn

func (conn *WSConn) Conn() *websocket.Conn

Conn 返回底层Conn

func (*WSConn) Read

func (conn *WSConn) Read(ch gnet.Channel) (interface{}, error)

func (*WSConn) SetReadLimit

func (conn *WSConn) SetReadLimit(readLimit int) error

SetReadLimit 设置websocket

func (*WSConn) Write

func (conn *WSConn) Write(ch gnet.Channel, data interface{}) error

type WSMessage

type WSMessage struct {
	Type int
	Data []byte
}

WSMessage 封装Websocket的消息格式

type WSServer

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

WSServer 使用WebSocket来实现

func NewWSServer

func NewWSServer(path, certFile, keyFile string, upgrader *websocket.Upgrader) *WSServer

NewWSServer 返回ws.Server

func (*WSServer) Close

func (server *WSServer) Close(bs *gnet.Bootstrap) error

Close 关闭服务端

func (*WSServer) Start

func (server *WSServer) Start(bs *gnet.Bootstrap) error

Start 启动服务端

Jump to

Keyboard shortcuts

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