Skip to content
This repository was archived by the owner on Sep 29, 2024. It is now read-only.
This repository was archived by the owner on Sep 29, 2024. It is now read-only.

Add general handlerFunc and context types #275

@sshaplygin

Description

@sshaplygin

After PR #274 i propose add new wrappers types similar as gin-gonic's types. It will be more comfortable and user friendly
New types propose will named as HandlerFunc and Context

Need implement on HandlerFunc next function interfaces:

  • onConnect: func(c Conn) error
  • onError: func(c Conn, err error)
  • onDisconnect: func(c Conn, msg string)
  • Event: func(c Conn, msg string) string / func(c Conn, msg string)

I propose to refactor OnConnect method to union interface func(c Conn) without returned error to func(c Conn, err error)

Context will be contain:

connect Conn, 
message string
err error

Feature usage example:

func OnConnectMainHandler () socketio.HandlerFunc {
	//NOTICE: add some middleware logic
	return func(context *socketio.Context) {
		context.connect.SetContext("")
		fmt.Println("connected:", s.ID())
		return nil
	}
}

// Add to server OnConnect event
server.OnConnect("/", OnConnectIndexHandler());

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions