Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit d5bd34e

Browse files
Apply suggestions from code review
Co-authored-by: Ryan Cartwright <[email protected]>
1 parent fc19248 commit d5bd34e

File tree

2 files changed

+15
-37
lines changed

2 files changed

+15
-37
lines changed

docs/guides/go/realtime-messaging.mdx

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,6 @@ func main() {
9090
// Initialize a KV store named "connections" with Get, Set, and Delete permissions.
9191
connections := nitric.NewKv("connections").Allow(keyvalue.KvStoreGet, keyvalue.KvStoreSet, keyvalue.KvStoreDelete)
9292

93-
// Handle new WebSocket connections by storing the connection ID in the KV store.
94-
ws.On(websockets.EventType_Connect, func(ctx *websockets.Ctx) {
95-
err := connections.Set(context.TODO(), ctx.Request.ConnectionID(), map[string]interface{}{
96-
"connectionId": ctx.Request.ConnectionID(),
97-
})
98-
if err != nil {
99-
return
100-
}
101-
})
102-
10393
// Add event handlers here
10494

10595
nitric.Run()
@@ -108,8 +98,8 @@ func main() {
10898

10999
Here we're creating:
110100

111-
- A WebSocket endpoint named `public`
112-
- A Key-Value store named `connections` to track WebSocket connections
101+
- A [WebSocket](/websockets) endpoint named `public`
102+
- A [Key-Value store](/keyvalue) named `connections` to track WebSocket connections
113103

114104
From here, let's add some features to that function that allow us to manage connections and broadcast messages.
115105

@@ -150,6 +140,7 @@ ws.On(websockets.EventType_Message, func(ctx *websockets.Ctx) {
150140
if err != nil {
151141
return
152142
}
143+
153144
senderId := ctx.Request.ConnectionID()
154145

155146
for {
@@ -205,15 +196,6 @@ func main() {
205196
}
206197
})
207198

208-
ws.On(websockets.EventType_Connect, func(ctx *websockets.Ctx) {
209-
err := connections.Set(context.TODO(), ctx.Request.ConnectionID(), map[string]interface{}{
210-
"connectionId": ctx.Request.ConnectionID(),
211-
})
212-
if err != nil {
213-
return
214-
}
215-
})
216-
217199
ws.On(websockets.EventType_Disconnect, func(ctx *websockets.Ctx) {
218200
err := connections.Delete(context.TODO(), ctx.Request.ConnectionID())
219201
if err != nil {
@@ -263,17 +245,13 @@ Now that you have your WebSocket application defined with handlers for each even
263245
nitric start
264246
```
265247

266-
Once it starts, the application will be ready to accept WebSocket connections. You can use a WebSocket client like Postman or any other WebSocket tool to test the application.
248+
Once it starts, the application will be ready to accept WebSocket connections. You can use a WebSocket client like Postman or any other WebSocket tool to test the application. Alternatively, you can use the [Nitric Dashboard](/get-started/foundations/projects/local-development#local-dashboard).
267249

268-
We will keep it running for our tests. If you want to update your services, just save them, and they'll be reloaded automatically.
250+
We will keep it running for our tests.
269251

270252
## Deploy to the cloud
271253

272-
At this point, you can deploy what you've built to any of the supported cloud providers. To do this, start by setting up your credentials and any configuration for the cloud you prefer:
273-
274-
- [AWS](/reference/providers/aws)
275-
- [Azure](/reference/providers/azure)
276-
- [GCP](/reference/providers/gcp)
254+
At this point, you can deploy what you've built to any of the supported cloud providers. To do this, start by setting up your credentials and configuration for [AWS](/providers/pulumi/aws).
277255

278256
Next, we'll need to create a `stack`. A stack represents a deployed instance of an application, which is a key value store of resources defined in your project. You might want separate stacks for each environment, such as stacks for `dev`, `test`, and `prod`. For now, let's start by creating a `dev` stack.
279257

docs/guides/terraform/terratest.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
description: Use Terratest to validate the infrastructure of a Nitric GO project deployed with Terraform
2+
description: Use Terratest to validate the infrastructure of a Nitric Go project deployed with Terraform
33
tags:
44
- Terraform
55
- Testing
@@ -13,10 +13,10 @@ This guide will walk you through adding [Terratest](https://terratest.gruntwork.
1313

1414
Terratest is designed to automate the entire process of testing your Terraform code with the following steps:
1515

16-
- **Initialize**: Terratest will automatically run terraform init to initialize the Terraform working directory.
17-
- **Apply**: It will then run terraform apply to deploy the infrastructure as defined in your Terraform code.
16+
- **Initialize**: Terratest will automatically run `terraform init` to initialize the Terraform working directory.
17+
- **Apply**: It will then run `terraform apply` to deploy the infrastructure as defined in your Terraform code.
1818
- **Assert**: The test script will then run assertions to check that the infrastructure was created as expected.
19-
- **Teardown**: Finally, it will run terraform destroy to tear down the infrastructure after the test completes.
19+
- **Teardown**: Finally, it will run `terraform destroy` to tear down the infrastructure after the test completes.
2020

2121
## What we'll be doing
2222

@@ -26,7 +26,7 @@ Terratest is designed to automate the entire process of testing your Terraform c
2626

2727
## Create and set up your application.
2828

29-
Our sample project creates a real-time communication service using [websockets](/websockets) and a [key-value store](/keyvalue) for connections.
29+
Our sample project creates a real-time communication service using [WebSockets](/websockets) and a [key-value store](/keyvalue) for connections.
3030

3131
We intend to deploy to AWS and will use Terratest to ensure that the following:
3232

@@ -113,7 +113,7 @@ func main() {
113113

114114
## Deploying to AWS with a Terraform provider
115115

116-
To deploy your application with Terraform you'll need to use Nitric's Terraform providers. You can learn more about using Nitric with Terraform [here](/reference/providers/terraform).
116+
To deploy your application with Terraform you'll need to use Nitric's Terraform providers. You can learn more about using Nitric with Terraform [here](/providers/terraform).
117117

118118
```
119119
nitric stack new dev aws-tf
@@ -156,7 +156,7 @@ go get github.com/aws/aws-sdk-go/aws/session
156156
go get github.com/aws/aws-sdk-go/service/apigatewayv2
157157
go get github.com/aws/aws-sdk-go/service/dynamodb
158158
go get github.com/aws/aws-sdk-go/service/iam
159-
```
159+
go get google.golang.org/genproto@latest
160160
161161
### Create the Test File
162162
@@ -208,11 +208,11 @@ func TestTerraformResources(t *testing.T) {
208208

209209
// Test IAM role creation
210210
iamClient := iam.New(sess)
211-
roleName := "go-realtime_services-hello" // Name of the IAM role to check
211+
roleName := "my-websocket-app_websockets-main" // Name of the IAM role to check
212212
_, err = iamClient.GetRole(&iam.GetRoleInput{
213213
RoleName: aws.String(roleName),
214214
})
215-
assert.NoError(t, err, "Expected IAM role 'go-realtime_services-hello' to be created")
215+
assert.NoError(t, err, "Expected IAM role 'my-websocket-app_websockets-main' to be created")
216216

217217
// Test API gateway webSocket creation
218218
apiClient := apigatewayv2.New(sess)

0 commit comments

Comments
 (0)