Some tools, I frequently use.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
819 B

package nhooyrioWebsocketAddons
import (
"context"
"nhooyr.io/websocket"
"nhooyr.io/websocket/wsjson"
)
func WsjsonSend(ctx context.Context, conn *websocket.Conn, sendval interface{}) (err error, receiveval interface{}) {
//Send
err = wsjson.Write(ctx, conn, sendval)
if err != nil {
return err, nil
}
//Receive
err = wsjson.Read(ctx, conn, &receiveval)
if err != nil {
return err, nil
}
return nil, receiveval
}
func WsjsonReceive(ctx context.Context, conn *websocket.Conn, dosth func(interface{}) interface{}) (err error, receiveval interface{}) {
err = nil
//Receive
err = wsjson.Read(ctx, conn, &receiveval)
if err != nil {
return
}
if dosth != nil {
receiveval = dosth(receiveval)
}
//Send
err = wsjson.Write(ctx, conn, sendval.(string))
if err != nil {
return
}
return
}