gmux

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: MIT Imports: 11 Imported by: 2

README

gmux

Documentation

Index

Constants

View Source
const (
	XPath       = "X-Path"
	XRealIP     = "X-Real-IP"
	ContentType = "Content-Type"
)
View Source
const (
	MimeJson   = "application/json; charset=utf-8"
	MimeStream = "application/octet-stream"
)

Variables

Functions

This section is empty.

Types

type A

type A map[string]interface{}

type Config

type Config struct {
	CodecHandle codec.Handle
	Validator   *validator.Validate
}

type Context

type Context struct {

	// 请求
	Request *Request
	// 响应写入器
	Writer ResponseWriter
	// contains filtered or unexported fields
}

Context 请求上下文

func NewContext

func NewContext(request *Request, writer ResponseWriter) *Context

func (*Context) BindJSON

func (c *Context) BindJSON(v interface{}) error

BindJSON 绑定请求数据

func (*Context) Get

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

Get 获取缓存内容

func (*Context) Next

func (c *Context) Next()

Next 执行下一个中间件

func (*Context) RawRequest

func (c *Context) RawRequest() interface{}

RawRequest 获取原生请求

func (*Context) RawResponseWriter

func (c *Context) RawResponseWriter() interface{}

RawResponseWriter 获取原生响应写入器

func (*Context) Set

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

Set 设置缓存内容

func (*Context) WriteBytes

func (c *Context) WriteBytes(code int, p []byte) error

WriteBytes 写入字节流

func (*Context) WriteJSON

func (c *Context) WriteJSON(code int, v interface{}) error

WriteJSON 写入JSON

func (*Context) WriteReader

func (c *Context) WriteReader(code int, r io.Reader) error

WriteReader 写入Reader

func (*Context) WriteString

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

WriteString 写入字节流

type F

type F map[string]string

func (F) Get

func (c F) Get(key string) string

func (F) Set

func (c F) Set(key, value string)

type Group

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

Group 路由组

func (*Group) Group

func (c *Group) Group(prefix string, middlewares ...HandlerFunc) *Group

Group 创建子路由组

func (*Group) On

func (c *Group) On(path string, handler HandlerFunc, middlewares ...HandlerFunc)

On 监听事件

type HandlerFunc

type HandlerFunc func(ctx *Context)

HandlerFunc 处理函数

type Header interface {
	Set(key, value string)
	Get(key string) string
}

type HeaderCodec

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

func NewHeaderCodec

func NewHeaderCodec(template Header, lengthEncoding HeaderLengthEncoding, handle codec.Handle) *HeaderCodec

func (*HeaderCodec) Decode

func (c *HeaderCodec) Decode(reader *bytes.Buffer) (Header, error)

func (*HeaderCodec) Encode

func (c *HeaderCodec) Encode(writer *bytes.Buffer, h Header) error

func (*HeaderCodec) NewHeader

func (c *HeaderCodec) NewHeader() Header

type HeaderLengthEncoding

type HeaderLengthEncoding uint8
const (
	BinaryLengthEncoding HeaderLengthEncoding = 2
	TextLengthEncoding   HeaderLengthEncoding = 4
)

type Option

type Option func(c *Config)

func WithCodecHandle

func WithCodecHandle(ch codec.Handle) Option

func WithValidator

func WithValidator(v *validator.Validate) Option

type Request

type Request struct {
	RawRequest interface{}
	Header     Header
	Body       io.Reader
}

Request 请求

type ResponseWriter

type ResponseWriter interface {
	Header() Header

	Write([]byte) (int, error)

	Code(code int)

	// Flush 刷新缓冲区
	Flush() error

	// RawResponseWriter 获取原生响应写入器
	RawResponseWriter() interface{}
}

ResponseWriter 响应写入器

type Router

type Router struct {
	HeaderCodec *HeaderCodec
	OnNoMatch   HandlerFunc
	// contains filtered or unexported fields
}

Router 路由器

func New

func New() *Router

New 创建路由器

func (*Router) Emit

func (c *Router) Emit(ctx *Context)

Emit 分发事件

func (*Router) Group

func (c *Router) Group(prefix string, middlewares ...HandlerFunc) *Group

Group 创建路由组

func (*Router) On

func (c *Router) On(path string, handler HandlerFunc, middlewares ...HandlerFunc)

On 监听事件

func (*Router) Use

func (c *Router) Use(middlewares ...HandlerFunc)

Use 设置全局中间件

Directories

Path Synopsis
contrib
adapter/gws Module
adapter/http Module
examples
gws

Jump to

Keyboard shortcuts

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