2 Respuestas
- Más nuevo
- Más votos
- Más comentarios
0
This method signature works. Would love some more docs/examples using golang. I have yet to successfully send a message through the socket.
type Response events.APIGatewayProxyResponse
func Handler(context context.Context, request events.APIGatewayWebsocketProxyRequest) (Response, error)
respondido hace 5 años
0
Hey NateN, not sure if you've figured this out, but I think I have a working solution for now?
I have one struct that I unmarshal the request body to EVERY TIME, no matter what the websocket action is (aside from connect/diconnect)
type WebSocketRequest struct {
Action string `json:"action"`
Data json.RawMessage `json:"data"`
}
webSocketRequest := &models.WebSocketRequest{}
if err := json.Unmarshal([]byte(request.Body), webSocketRequest); err != nil {
return payloads.GenerateErrorResponse(500, err), nil
}
Then for the sendMessage lambda from the example they have, I use this request struct
type sendMessageRequest struct {
Message string `json:"message"`
}
sendMessageRequest := &sendMessageRequest{}
if err := json.Unmarshal(webSocketRequest.Data, sendMessageRequest); err != nil {
return payloads.GenerateErrorResponse(500, err), nil
}
And here is my test message
{"action":"sendmessage","data":{"message":"sending a ws message to you! <3"}}
Hope this helps
respondido hace 5 años
Contenido relevante
- OFICIAL DE AWSActualizada hace 2 años
- OFICIAL DE AWSActualizada hace 2 años
- OFICIAL DE AWSActualizada hace 2 años
- OFICIAL DE AWSActualizada hace 2 años