README
¶
Streamer Quickstart - Lift v1.0.12
This is a complete working example of WebSocket support in Lift v1.0.12.
Quick Test
- Verify your Lift version:
go list -m github.com/pay-theory/lift
# Should show: github.com/pay-theory/lift v1.0.12
- If not v1.0.12, update it:
go get github.com/pay-theory/lift@v1.0.12
go mod tidy
- Build the example:
go build -o streamer main.go
- Deploy to AWS Lambda (example with SAM):
Create template.yaml:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
WebSocketApi:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: StreamerWebSocket
ProtocolType: WEBSOCKET
RouteSelectionExpression: "$request.body.action"
ConnectRoute:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref WebSocketApi
RouteKey: $connect
Target: !Sub integrations/${ConnectIntegration}
ConnectIntegration:
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref WebSocketApi
IntegrationType: AWS_PROXY
IntegrationUri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${StreamerFunction.Arn}/invocations
StreamerFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: streamer
Runtime: go1.x
Policies:
- Statement:
- Effect: Allow
Action:
- execute-api:ManageConnections
Resource: !Sub arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${WebSocketApi}/*
Testing Locally
You can test the handler logic locally:
package main
import (
"testing"
"github.com/pay-theory/lift/pkg/lift"
)
func TestWebSocketHandler(t *testing.T) {
app := lift.New(lift.WithWebSocketSupport())
// Your handler registration here
app.WebSocket("$connect", func(ctx *lift.Context) error {
return ctx.Status(200).JSON(map[string]string{
"status": "connected",
})
})
// Test it
// ... test code
}
Common Issues
"undefined: lift.WithWebSocketSupport"
- You're not using v1.0.12. Run:
go get github.com/pay-theory/lift@v1.0.12
"app.WebSocket undefined"
- Clear module cache:
go clean -modcache - Re-download:
go mod download
Build errors
- Make sure you have all dependencies:
go get github.com/aws/aws-lambda-go/lambda go get github.com/aws/aws-lambda-go/events
What This Example Shows
- Connection Management - Handling $connect and $disconnect
- Authentication - Using query parameters for auth tokens
- Message Routing - Routing messages based on action field
- Broadcasting - Using WebSocket context to send messages
- Error Handling - Proper error responses
Next Steps
- Add DynamoDB connection store for real connection management
- Implement room/channel functionality
- Add metrics and monitoring
- Set up CloudWatch logging
Need Help?
Run the verification script:
go run ../../scripts/verify-websocket-v1.0.12.go
This will check your environment and confirm WebSocket support is working.
Documentation
¶
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.