gldap
gldap copied to clipboard
Support for attach and fetch custom data with connection
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
}
🤔 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.
@xitianfz do you think my suggestion above (callback) would work well for your use-case/workflow?
@xitianfz do you think my suggestion above (callback) would work well for your use-case/workflow?
😀That's a good idea