njones / socketio

A Modern SocketIO library for go
MIT License
64 stars 9 forks source link

On callback return map[string]interface{} empty #66

Closed mmavka closed 1 year ago

mmavka commented 1 year ago

Hello. Thanks for the library I can't sort out the callback for On (subscription events). In server. I received empty map[string]interface. Can you help me this problem, maybe. thanks

I sending test message from Postman as JSON. Setting v4 or v3

Message ``` { "key": "value" } ```
Use code map ``` server.On("event", callback.Wrap{ Parameters: []ser.Serializable{ser.MapParam}, Func: func() interface{} { return func(msg map[string]interface{}) error { fmt.Println(msg) return nil } }, }) ```

I getting empty map. map[]

if I set StrParam

Use code string ``` server.On("event", callback.Wrap{ Parameters: []ser.Serializable{ser. StrParam}, Func: func() interface{} { return func(msg string) error { fmt.Println(msg) return nil } }, }) ```

then I getting string "map[key:value]"

njones commented 1 year ago

Hi mmavka,

Thanks for using the library! The callback.Wrap struct is supposed to be used for simple things, so it was only set to use reflection on scalar values, but a map seemed logical and easy to add. So I added it, and updated the examples with it. Also I updated examples on how to add a map as a custom callback, that's how you can do complex objects. You can see the examples linked here.

njones commented 1 year ago

The updated examples link is here.

mmavka commented 1 year ago

Thanks