gldap icon indicating copy to clipboard operation
gldap copied to clipboard

Support for attach and fetch custom data with connection

Open xitianfz opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe. Currently, in order to maintain connection session data, we can use Request.GetConnectionID() to build an extra session table. Normally the session will be cleared when an unbind request is received. But when the connection is closed without receiving an unbind request, the related session cannot be correctly cleared.

Describe the solution you'd like Provide methods to attach and fetch custom data with each connection:

type conn struct {
        ...
	extra interface{}
}

func (r *Request) SetConnectionExtra(value interface{}) {
	r.conn.extra = value
}
func (r *Request) GetConnectionExtra() interface{} {
	return r.conn.extra
}

xitianfz avatar Oct 11 '22 03:10 xitianfz

🤔 I wonder if it might be better to add an optional OnClose(connectionID string) callback which can be specified when you create a NewServer(...)? This would allow devs to provide whatever clean up function they need which is called whenever a connection is closed.

jimlambrt avatar Oct 16 '22 11:10 jimlambrt

@xitianfz do you think my suggestion above (callback) would work well for your use-case/workflow?

jimlambrt avatar Oct 17 '22 11:10 jimlambrt

@xitianfz do you think my suggestion above (callback) would work well for your use-case/workflow?

😀That's a good idea

xitianfz avatar Nov 02 '22 08:11 xitianfz