Skip to content

Commit

Permalink
Merge pull request #320 from aceld/feature/aceld
Browse files Browse the repository at this point in the history
Organize code comments
  • Loading branch information
aceld authored Apr 29, 2024
2 parents 692cfcf + fff5766 commit 0a2ab19
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 101 deletions.
2 changes: 1 addition & 1 deletion ziface/iconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/gorilla/websocket"
)

// // Define connection interface
// IConnection Define connection interface
type IConnection interface {
// Start the connection, make the current connection start working
// (启动连接,让当前连接开始工作)
Expand Down
4 changes: 1 addition & 3 deletions ziface/iconnmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// @Author Aceld - Thu Mar 11 10:32:29 CST 2019
package ziface

/*
IConnManager Connection Management Abstract Layer
*/
// IConnManager Connection Management Abstract Layer
type IConnManager interface {
Add(IConnection) // Add connection
Remove(IConnection) // Remove connection
Expand Down
9 changes: 3 additions & 6 deletions ziface/idatapack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
// @Author Aceld - Thu Mar 11 10:32:29 CST 2019
package ziface

/*
IDataPack Package and unpack data.
Operating on the data stream of TCP connections, add header information to transfer data, and solve TCP sticky packets.
(封包数据和拆包数据
直接面向TCP连接中的数据流,为传输数据添加头部信息,用于处理TCP粘包问题。)
*/
// IDataPack Package and unpack data.
// Operating on the data stream of TCP connections, add header information to transfer data, and solve TCP sticky packets.
// (封包数据和拆包数据, 直接面向TCP连接中的数据流,为传输数据添加头部信息,用于处理TCP粘包问题。)
type IDataPack interface {
GetHeadLen() uint32 // Get the length of the message header(获取包头长度方法)
Pack(msg IMessage) ([]byte, error) // Package message (封包方法)
Expand Down
26 changes: 11 additions & 15 deletions ziface/irouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,23 @@
// @Author Aceld - Thu Mar 11 10:32:29 CST 2019
package ziface

/*
IRouter is the interface for message routing. The route is the processing
business method set by the framework user for this connection. The IRequest
in the route includes the connection information and the request data
information for this connection.
(路由接口, 这里面路由是 使用框架者给该链接自定的 处理业务方法
路由里的IRequest 则包含用该链接的链接信息和该链接的请求数据信息)
*/
// IRouter is the interface for message routing. The route is the processing
// business method set by the framework user for this connection. The IRequest
// in the route includes the connection information and the request data
// information for this connection.
// (路由接口, 这里面路由是 使用框架者给该链接自定的 处理业务方法
// 路由里的IRequest 则包含用该链接的链接信息和该链接的请求数据信息)
type IRouter interface {
PreHandle(request IRequest) //Hook method before processing conn business(在处理conn业务之前的钩子方法)
Handle(request IRequest) //Method for processing conn business(处理conn业务的方法)
PostHandle(request IRequest) //Hook method after processing conn business(处理conn业务之后的钩子方法)
}

/*
RouterHandler is a method slice collection style router. Unlike the old version,
the new version only saves the router method collection, and the specific execution
is handed over to the IRequest of each request.
(方法切片集合式路路由
不同于旧版 新版本仅保存路由方法集合,具体执行交给每个请求的 IRequest)
*/
// RouterHandler is a method slice collection style router. Unlike the old version,
// the new version only saves the router method collection, and the specific execution
// is handed over to the IRequest of each request.
// (方法切片集合式路路由
// 不同于旧版 新版本仅保存路由方法集合,具体执行交给每个请求的 IRequest)
type RouterHandler func(request IRequest)
type IRouterSlices interface {
// Add global components (添加全局组件)
Expand Down
13 changes: 6 additions & 7 deletions zinterceptor/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* @date 15:56 2023/3/10
* @description 责任链模式
**/

package zinterceptor

import "github.com/aceld/zinx/ziface"
Expand Down Expand Up @@ -36,7 +35,7 @@ func (c *Chain) Proceed(request ziface.IcReq) ziface.IcResp {
return request
}

// GetIMessage 从Chain中获取IMessage
// GetIMessage Get IMessage from the Chain (从Chain中获取IMessage)
func (c *Chain) GetIMessage() ziface.IMessage {

req := c.Request()
Expand All @@ -52,9 +51,8 @@ func (c *Chain) GetIMessage() ziface.IMessage {
return iRequest.GetMessage()
}

// Next 通过IMessage和解码后数据进入下一个责任链任务
// iMessage 为解码后的IMessage
// response 为解码后的数据
// Next Enter the next chain task with IMessage and decoded data,iMessage is the decoded IMessage response is the decoded data
// (Next 通过IMessage和解码后数据进入下一个责任链任务, iMessage 为解码后的IMessage, response 为解码后的数据)
func (c *Chain) ProceedWithIMessage(iMessage ziface.IMessage, response ziface.IcReq) ziface.IcResp {
if iMessage == nil || response == nil {
return c.Proceed(c.Request())
Expand All @@ -70,13 +68,14 @@ func (c *Chain) ProceedWithIMessage(iMessage ziface.IMessage, response ziface.Ic
return c.Proceed(c.Request())
}

//设置chain的request下一次请求
// Set the request of chain for the next request
// (设置chain的request下一次请求)
iRequest.SetResponse(response)

return c.Proceed(iRequest)
}

// ShouldIRequest 判断是否是IRequest
// ShouldIRequest Determine if it is IRequest(判断是否是IRequest)
func (c *Chain) ShouldIRequest(icReq ziface.IcReq) ziface.IRequest {
if icReq == nil {
return nil
Expand Down
Loading

0 comments on commit 0a2ab19

Please sign in to comment.