router

package
v0.0.42 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

路由处理

介绍

  • 2022/11/28

描述

  • 此包是对路由的处理

自定义代理示例

  • 必须实现 Proxy 接口
type C struct {
	proxy Proxy
}

func (p *C) InvokeFunc(msg message.Message) []byte {
	router.FileLogger().Println("C执行")
	invokeFunc := p.proxy.InvokeFunc(msg)
	router.FileLogger().Println("C之后")
	return invokeFunc
}
func (p *C) SetProxy(proxy Proxy) {
	p.proxy = proxy
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileLogger added in v0.0.12

func FileLogger() *log.Logger

FileLogger 写入文件日志 -> 记录一些可能不重要的日志,例如客户端主动断开的错误。

func LogFunc added in v0.0.11

func LogFunc(merge int64, f func(ctx *Context))

func LogFuncTime added in v0.0.11

func LogFuncTime(merge int64, time string)

func LogPrint added in v0.0.11

func LogPrint(format string, values ...any)

Types

type Context

type Context struct {
	// 具体消息 -> 当这个消息为空时则不返回数据回去
	Message messages.Message
	// Rpc服务 -> 服务
	RpcServer remote.RpcServer
	// 链接Id -> 连接建立时的唯一id
	SocketId uint32
	// 网关服的RpcIp,单机模式此处为空。将会传递到逻辑服当中
	RpcIp string
	// data
	Data any
}

func (*Context) Result added in v0.0.42

func (c *Context) Result(data any)

注入返回结果

type DefaultRouter

type DefaultRouter struct {

	// 日志开启
	DebugLog bool
	// 跳过某个路由日志
	SkipLogMap map[int64]bool
	// contains filtered or unexported fields
}

DefaultRouter 路由功能

func (*DefaultRouter) Action added in v0.0.39

func (r *DefaultRouter) Action(cmd, subCmd int64, method func(msg *Context))

Action 添加函数

func (*DefaultRouter) AddProxy

func (r *DefaultRouter) AddProxy(proxy Proxy)

AddProxy 添加代理器,最先添加的最最后执行。 异常中间件应该在最后添加机,用于捕获所有异常 ProxyFunc

func (*DefaultRouter) AddSkipLog added in v0.0.24

func (r *DefaultRouter) AddSkipLog(cmd, subCmd int64)

AddSkipLog 添加排除日志方法

func (*DefaultRouter) ExecuteMethod

func (r *DefaultRouter) ExecuteMethod(msg *Context)

func (*DefaultRouter) InvokeFunc

func (r *DefaultRouter) InvokeFunc(ctx *Context)

InvokeFunc 代理函数执行

func (*DefaultRouter) SetProxy

func (r *DefaultRouter) SetProxy(proxy Proxy)

type ErrProxy added in v0.0.24

type ErrProxy struct {
	ProxyFunc
}

func (*ErrProxy) InvokeFunc added in v0.0.24

func (e *ErrProxy) InvokeFunc(ctx *Context)

type H added in v0.0.37

type H map[string]interface{}

type M added in v0.0.37

type M map[string]bool

type Proxy

type Proxy interface {
	// InvokeFunc 调用函数
	InvokeFunc(ctx *Context)
	// SetProxy 默认目标对象是A 你编写了B代理 -> 那么A将会传递下去,所以你在代理类需要调用代理对象的方法
	SetProxy(proxy Proxy)
}

type ProxyFunc

type ProxyFunc struct {
	Proxy Proxy
}

ProxyFunc 代理模型

func (*ProxyFunc) InvokeFunc

func (p *ProxyFunc) InvokeFunc(ctx *Context)

func (*ProxyFunc) SetProxy

func (p *ProxyFunc) SetProxy(proxy Proxy)

type Router

type Router interface {
	// Action 添加路由
	Action(cmd, subCmd int64, method func(ctx *Context))
	// ExecuteMethod 执行函数
	ExecuteMethod(msg *Context)
	// AddProxy 添加代理
	AddProxy(proxy Proxy)
}

Router 路由器功能

type ServiceError added in v0.0.24

type ServiceError struct {
	Code    int
	Message string
	// contains filtered or unexported fields
}

func NewServiceError added in v0.0.24

func NewServiceError(code int, message string) *ServiceError

Jump to

Keyboard shortcuts

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