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

Commit e27a05a

Browse files
update old sdk references
1 parent 4daaaee commit e27a05a

File tree

7 files changed

+29
-29
lines changed

7 files changed

+29
-29
lines changed

src/pages/apis.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,14 @@ async function validate(ctx, next) {
582582
```python
583583
async def validate(ctx, nxt: HttpMiddleware):
584584
if ctx.req.headers['content-type'] is None:
585-
ctx.res.status = 400;
585+
ctx.res.status = 400
586586
ctx.res.body = "header Content-Type is required"
587587
return ctx
588588
return await nxt(ctx)
589589
```
590590

591591
```go
592-
func validate(ctx *apis.Ctx, next nitric.Handler[apis.Ctx]) (*handler.HttpContext, error) {
592+
func validate(ctx *apis.Ctx, next nitric.Handler[apis.Ctx]) (*apis.Ctx, error) {
593593
if ctx.Request.Headers()["content-type"] != nil {
594594
ctx.Response.Status = 400
595595
ctx.Response.Body = []byte("header Content-Type is required")

src/pages/reference/go/storage/bucket-on.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ func main() {
2222
return
2323
}
2424

25-
assets.On(handler.DeleteNotification, "*", func(ctx *storage.Ctx) {
25+
assets.On(storage.DeleteNotification, "*", func(ctx *storage.Ctx) {
2626
fmt.Printf("a file named %s was deleted\n", ctx.Request.Key())
2727
})
2828

29-
assets.On(handler.WriteNotification, "/images/cat", func(ctx *storage.Ctx) {
29+
assets.On(storage.WriteNotification, "/images/cat", func(ctx *storage.Ctx) {
3030
fmt.Printf("a cat image was written")
3131
})
3232

33-
assets.On(handler.WriteNotification, "/images/dog", func(ctx *storage.Ctx) error {
33+
assets.On(storage.WriteNotification, "/images/dog", func(ctx *storage.Ctx) error {
3434
dogImage, err := readableAssets.Read(context.TODO(), ctx.Request.Key())
3535
if err != nil {
3636
return err

src/pages/reference/go/websocket/websocket-close.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func main() {
5858
}
5959

6060
// Broadcast message to all the registered websocket connections
61-
ws.On(handler.WebsocketMessage, func(ctx *websockets.Ctx) (*websockets.Ctx, error) {
61+
ws.On(websockets.EventType_Message, func(ctx *websockets.Ctx) (*websockets.Ctx, error) {
6262
if ctx.Request.Message() == "close" {
6363
err := ws.Close(context.Background(), ctx.Request.ConnectionID())
6464
return ctx, err

src/pages/reference/go/websocket/websocket-on.mdx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ func main() {
1919
return
2020
}
2121

22-
ws.On(handler.WebsocketConnect, func(ctx *websockets.Ctx) {
22+
ws.On(websockets.EventType_Connect, func(ctx *websockets.Ctx) {
2323
// handle connections
2424
})
2525

26-
ws.On(handler.WebsocketDisconnect, func(ctx *websockets.Ctx) {
26+
ws.On(websockets.EventType_Disconnect, func(ctx *websockets.Ctx) {
2727
// handle disconnections
2828
})
2929

30-
ws.On(handler.WebsocketMessage, func(ctx *websockets.Ctx) {
30+
ws.On(websockets.EventType_Message, func(ctx *websockets.Ctx) {
3131
// handle messages
3232
})
3333

@@ -41,8 +41,8 @@ func main() {
4141

4242
<Properties>
4343
<Property name="eventType" required type="WebsocketEventType">
44-
The type of websocket event to listen for. Can be `WebsocketConnect`,
45-
`WebsocketDisconnect`, or `WebsocketMessage`.
44+
The type of websocket event to listen for. Can be `EventType_Connect`,
45+
`EventType_Disconnect`, or `EventType_Message`.
4646
</Property>
4747
<Property name="middleware" required type="...interface{}">
4848
The middleware function to use as the handler for Websocket events. If you
@@ -55,7 +55,7 @@ func main() {
5555
### Register a handler for message events
5656

5757
```go
58-
ws.On(handler.WebsocketMessage, func(ctx *websockets.Ctx) {
58+
ws.On(websockets.EventType_Message, func(ctx *websockets.Ctx) {
5959
fmt.Printf("New Message from %s: %s\n", ctx.Request.ConnectionID(), ctx.Request.Message())
6060
})
6161
```
@@ -85,19 +85,19 @@ func main() {
8585
}
8686

8787
// Register a new connection on connect
88-
ws.On(handler.WebsocketConnect, func(ctx *websockets.Ctx) error {
88+
ws.On(websockets.EventType_Connect, func(ctx *websockets.Ctx) error {
8989
return := connections.Set(context.TODO(), ctx.Request.ConnectionID(), map[string]interface{}{
9090
"connectionId": ctx.Request.ConnectionID(),
9191
})
9292
})
9393

9494
// Remove a registered connection on disconnect
95-
ws.On(handler.WebsocketDisconnect, func(ctx *websockets.Ctx) error {
95+
ws.On(websockets.EventType_Disconnect, func(ctx *websockets.Ctx) error {
9696
return connections.Delete(context.TODO(), ctx.Request.ConnectionID())
9797
})
9898

9999
// Broadcast message to all the registered websocket connections
100-
ws.On(handler.WebsocketMessage, func(ctx *websockets.Ctx) error {
100+
ws.On(websockets.EventType_Message, func(ctx *websockets.Ctx) error {
101101
connectionStream, err := connections.Keys(context.TODO())
102102
if err != nil {
103103
return ctx, err
@@ -151,7 +151,7 @@ func main() {
151151
return
152152
}
153153

154-
ws.On(handler.WebsocketMessage, validateMessage, handleMessage)
154+
ws.On(websockets.EventType_Message, validateMessage, handleMessage)
155155

156156
if err := nitric.Run(); err != nil {
157157
fmt.Println(err)

src/pages/reference/go/websocket/websocket-send.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ func main() {
7171
}
7272

7373
// Register a new connection on connect
74-
ws.On(handler.WebsocketConnect, func(ctx *websockets.Ctx) error {
74+
ws.On(websockets.EventType_Connect, func(ctx *websockets.Ctx) error {
7575
return connections.Set(context.TODO(), ctx.Request.ConnectionID(), map[string]interface{}{
7676
"connectionId": ctx.Request.ConnectionID(),
7777
})
7878
})
7979

8080
// Remove a registered connection on disconnect
81-
ws.On(handler.WebsocketDisconnect, func(ctx *websockets.Ctx) error {
81+
ws.On(websockets.EventType_Disconnect, func(ctx *websockets.Ctx) error {
8282
return connections.Delete(context.TODO(), ctx.Request.ConnectionID())
8383
})
8484

8585
// Broadcast message to all the registered websocket connections
86-
ws.On(handler.WebsocketMessage, func(ctx *websockets.Ctx) error {
86+
ws.On(websockets.EventType_Message, func(ctx *websockets.Ctx) error {
8787
connectionStream, err := connections.Keys(context.TODO())
8888
if err != nil {
8989
return err

src/pages/storage.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ func main() {
522522
profiles := nitric.NewBucket("profiles")
523523

524524
// Filter for 'write' events for files starting with '/users/images'
525-
profiles.On(handler.WriteNotification, "/users/images", func(ctx *storage.Ctx) {
525+
profiles.On(storage.WriteNotification, "/users/images", func(ctx *storage.Ctx) {
526526
fmt.Printf("new profile image for %s was written", ctx.Request.Key())
527527
})
528528

@@ -588,7 +588,7 @@ func main() {
588588
profiles := nitric.NewBucket("profiles")
589589

590590
// Filter for 'delete' events for any file
591-
profiles.On(handler.DeleteNotification, "*", func(ctx *storage.Ctx) {
591+
profiles.On(storage.DeleteNotification, "*", func(ctx *storage.Ctx) {
592592
fmt.Printf("%s was deleted", ctx.Request.Key())
593593
})
594594

src/pages/websockets.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ import (
6666
func main() {
6767
socket, _ := nitric.NewWebsocket("socket")
6868

69-
socket.On(handler.WebsocketConnect, func(ctx *websockets.Ctx) {
69+
socket.On(websockets.EventType_Connect, func(ctx *websockets.Ctx) {
7070
// handle connections
7171
})
7272

73-
socket.On(handler.WebsocketDisconnect, func(ctx *websockets.Ctx) {
73+
socket.On(websockets.EventType_Disconnect, func(ctx *websockets.Ctx) {
7474
// handle disconnections
7575
})
7676

77-
socket.On(handler.WebsocketMessage, func(ctx *websockets.Ctx) {
77+
socket.On(websockets.EventType_Message, func(ctx *websockets.Ctx) {
7878
// handle messages
7979
})
8080

@@ -175,15 +175,15 @@ func main() {
175175
connections, _ := nitric.NewKv("connections").Allow(nitric.KvStoreGet, nitric.KvStoreSet, nitric.KvStoreDelete)
176176

177177
// Register a new connection on connect
178-
socket.On(handler.WebsocketConnect, func(ctx *websockets.Ctx) {
178+
socket.On(websockets.EventType_Connect, func(ctx *websockets.Ctx) {
179179
_ = connections.Set(context.TODO(), ctx.Request.ConnectionID(), map[string]interface{}{
180180
// Store any metadata related to the connection here
181181
"connectionId": ctx.Request.ConnectionID(),
182182
})
183183
})
184184

185185
// Remove a registered connection on disconnect
186-
socket.On(handler.WebsocketDisconnect, func(ctx *websockets.Ctx) {
186+
socket.On(websockets.EventType_Disconnect, func(ctx *websockets.Ctx) {
187187
_ = connections.Delete(context.TODO(), ctx.Request.ConnectionID())
188188
})
189189

@@ -315,20 +315,20 @@ func main() {
315315
connections, _ := nitric.NewKv("connections").Allow(nitric.KvStoreGet, nitric.KvStoreSet, nitric.KvStoreDelete)
316316

317317
// Register a new connection on connect
318-
socket.On(handler.WebsocketConnect, func(ctx *websockets.Ctx) {
318+
socket.On(websockets.EventType_Connect, func(ctx *websockets.Ctx) {
319319
_ = connections.Set(context.TODO(), ctx.Request.ConnectionID(), map[string]interface{}{
320320
// Store any metadata related to the connection here
321321
"connectionId": ctx.Request.ConnectionID(),
322322
})
323323
})
324324

325325
// Remove a registered connection on disconnect
326-
socket.On(handler.WebsocketDisconnect, func(ctx *websockets.Ctx) {
326+
socket.On(websockets.EventType_Disconnnect, func(ctx *websockets.Ctx) {
327327
_ = connections.Delete(context.TODO(), ctx.Request.ConnectionID())
328328
})
329329

330330
// Broadcast message to all the registered websocket connections
331-
socket.On(handler.WebsocketMessage, func(ctx *websockets.Ctx) {
331+
socket.On(websockets.EventType_Message, func(ctx *websockets.Ctx) {
332332
connectionStream, _ := connections.Keys(context.TODO())
333333

334334
for {

0 commit comments

Comments
 (0)