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

Commit 9fc9372

Browse files
committed
cleanup older sdk references.
1 parent 8098ab5 commit 9fc9372

File tree

10 files changed

+35
-82
lines changed

10 files changed

+35
-82
lines changed

src/pages/getting-started/quickstart.mdx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ package main
272272
import (
273273
"fmt"
274274

275-
"github.com/nitrictech/go-sdk/handler"
275+
"github.com/nitrictech/go-sdk/nitric/apis"
276276
"github.com/nitrictech/go-sdk/nitric"
277277
)
278278

@@ -283,25 +283,19 @@ func main() {
283283
return
284284
}
285285

286-
api.Get("/hello/:name", func(ctx *handler.HttpContext, next handler.HttpHandler) (*handler.HttpContext, error) {
286+
api.Get("/hello/:name", func(ctx *apis.Ctx) {
287287
name := ctx.Request.PathParams()["name"]
288288
ctx.Response.Body = []byte(fmt.Sprintf("Hello %s", name))
289-
290-
return next(ctx)
291289
})
292290

293-
api.Get("/goodbye/:name", func(ctx *handler.HttpContext, next handler.HttpHandler) (*handler.HttpContext, error) {
291+
api.Get("/goodbye/:name", func(ctx *apis.Ctx) {
294292
name := ctx.Request.PathParams()["name"]
295293
ctx.Response.Body = []byte(fmt.Sprintf("Goodbye %s", name))
296-
297-
return next(ctx)
298294
})
299295

300296
if err := nitric.Run(); err != nil {
301297
fmt.Println(err)
302298
}
303-
304-
fmt.Println("Service has started")
305299
}
306300
```
307301

src/pages/getting-started/resources-overview.mdx

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ package main
5656
import (
5757
"fmt"
5858

59-
"github.com/nitrictech/go-sdk/handler"
59+
"github.com/nitrictech/go-sdk/nitric/apis"
6060
"github.com/nitrictech/go-sdk/nitric"
6161
)
6262

@@ -70,11 +70,9 @@ func main() {
7070
// ✅ This declaration will work
7171
bucket, err := nitric.NewBucket("files").Allow(nitric.BucketRead)
7272

73-
api.Get("/files/:name", func(ctx *handler.HttpContext, next handler.HttpHandler) (*handler.HttpContext, error) {
73+
api.Get("/files/:name", func(ctx *apis.Ctx) {
7474
// ❌ This declaration will not work, as this is only called at runtime.
7575
badBucket, err := nitric.NewBucket("wont-work").Allow(nitric.BucketRead)
76-
77-
return next(ctx)
7876
})
7977

8078
if err := nitric.Run(); err != nil {
@@ -155,7 +153,7 @@ package main
155153
import (
156154
"fmt"
157155

158-
"github.com/nitrictech/go-sdk/handler"
156+
"github.com/nitrictech/go-sdk/nitric/apis"
159157
"github.com/nitrictech/go-sdk/nitric"
160158
)
161159

@@ -170,20 +168,16 @@ func main() {
170168
bucket, err := nitric.NewBucket("files").Allow(nitric.BucketRead)
171169

172170
// ❌ This access will not work
173-
fileContents, _ := bucket.File("example.txt").Read()
171+
fileContents, _ := bucket.Read(context.TODO(), "example.txt")
174172

175-
api.Get("/files/:name", func(ctx *handler.HttpContext, next handler.HttpHandler) (*handler.HttpContext, error) {
173+
api.Get("/files/:name", func(ctx *apis.Ctx) {
176174
// ✅ This access will work
177-
fileContents, _ := bucket.File("example.txt").Read()
178-
179-
return next(ctx)
175+
fileContents, _ := bucket.Read(context.TODO(), "example.txt")
180176
})
181177

182178
if err := nitric.Run(); err != nil {
183179
fmt.Println(err)
184180
}
185-
186-
fmt.Println("Service has started")
187181
}
188182
```
189183

@@ -329,7 +323,6 @@ import (
329323
"context"
330324
"fmt"
331325

332-
"github.com/nitrictech/go-sdk/handler"
333326
"github.com/nitrictech/go-sdk/nitric"
334327
"github.com/nitrictech/your-org/your-repo/resources"
335328
)
@@ -340,19 +333,15 @@ func main() {
340333
panic(err)
341334
}
342335

343-
resources.PublicApi.Post("/update", func(ctx *handler.HttpContext, next handler.HttpHandler) (*handler.HttpContext, error) {
336+
resources.PublicApi.Post("/update", func() {
344337
publisher.Publish(context.TODO(), map[string]interface{}{
345338
"test": "message",
346339
})
347-
348-
return next(ctx)
349340
})
350341

351342
if err := nitric.Run(); err != nil {
352343
fmt.Println(err)
353344
}
354-
355-
fmt.Println("Api service has started")
356345
}
357346

358347

@@ -362,16 +351,13 @@ package main
362351
import (
363352
"fmt"
364353

365-
"github.com/nitrictech/go-sdk/handler"
366354
"github.com/nitrictech/go-sdk/nitric"
367355
"github.com/nitrictech/your-org/your-repo/resources"
368356
)
369357

370358
func main() {
371-
resources.UpdateTopic.Subscribe(func(mc *handler.MessageContext, mh handler.MessageHandler) (*handler.MessageContext, error) {
359+
resources.UpdateTopic.Subscribe(func() {
372360
println("got the message")
373-
374-
return mc, nil
375361
})
376362

377363
if err := nitric.Run(); err != nil {
@@ -516,22 +502,19 @@ package main
516502
import (
517503
"fmt"
518504

519-
"github.com/nitrictech/go-sdk/handler"
505+
"github.com/nitrictech/go-sdk/nitric/apis"
520506
"github.com/nitrictech/go-sdk/nitric"
521507
"github.com/your-org/your-repo/resources"
522508
)
523509

524510
func main() {
525-
resources.PublicApi.Get("/bucket-one/file/:name", func(hc *handler.HttpContext, next handler.HttpHandler) (*handler.HttpContext, error) {
511+
resources.PublicApi.Get("/bucket-one/file/:name", func(ctx *apis.Ctx) {
526512
// do something with the file
527-
return next(hc)
528513
})
529514

530515
if err := nitric.Run(); err != nil {
531516
fmt.Println(err)
532517
}
533-
534-
fmt.Println("Service has started")
535518
}
536519

537520
// services/service-two/main.go
@@ -540,22 +523,19 @@ package main
540523
import (
541524
"fmt"
542525

543-
"github.com/nitrictech/go-sdk/handler"
526+
"github.com/nitrictech/go-sdk/nitric/apis"
544527
"github.com/nitrictech/go-sdk/nitric"
545528
"github.com/your-org/your-repo/resources"
546529
)
547530

548531
func main() {
549-
resources.PublicApi.Get("/bucket-two/file/:name", func(hc *handler.HttpContext, next handler.HttpHandler) (*handler.HttpContext, error) {
532+
resources.PublicApi.Get("/bucket-two/file/:name", func(hc *apis.Ctx) {
550533
// do something with the file
551-
return next(hc)
552534
})
553535

554536
if err := nitric.Run(); err != nil {
555537
fmt.Println(err)
556538
}
557-
558-
fmt.Println("Service has started")
559539
}
560540
```
561541

src/pages/reference/go/api/api-route-all.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ For methods that include a request body, such as `POST` and `PUT`, you can acces
162162
import (
163163
"fmt"
164164

165-
"github.com/nitrictech/go-sdk/handler"
165+
"github.com/nitrictech/go-sdk/nitric/apis"
166166
"github.com/nitrictech/go-sdk/nitric"
167167
)
168168

src/pages/reference/go/api/api-route.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Creates a new route (path) within an API.
99
import (
1010
"fmt"
1111

12-
"github.com/nitrictech/go-sdk/handler"
1312
"github.com/nitrictech/go-sdk/nitric"
1413
)
1514

@@ -53,7 +52,6 @@ func main() {
5352
import (
5453
"fmt"
5554

56-
"github.com/nitrictech/go-sdk/handler"
5755
"github.com/nitrictech/go-sdk/nitric"
5856
)
5957

@@ -81,7 +79,6 @@ For example, if you have a customers path and you want to include a `customerId`
8179
import (
8280
"fmt"
8381

84-
"github.com/nitrictech/go-sdk/handler"
8582
"github.com/nitrictech/go-sdk/nitric"
8683
)
8784

@@ -106,11 +103,11 @@ func main() {
106103
import (
107104
"fmt"
108105

109-
"github.com/nitrictech/go-sdk/handler"
106+
"github.com/nitrictech/go-sdk/nitric/apis"
110107
"github.com/nitrictech/go-sdk/nitric"
111108
)
112109

113-
func authMiddleware(ctx *handler.HttpContext, next handler.HttpHandler) (*handler.HttpContext, error) {
110+
func authMiddleware(ctx *apis.Ctx, next nitric.Handler[apis.Ctx]) (*apis.Ctx, error) {
114111
// Perform auth validation
115112
return next(ctx)
116113
}

src/pages/reference/go/schedule/schedule-cron.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Sets the cron expressions that determines when the schedule triggers and a callb
99
import (
1010
"fmt"
1111

12-
"github.com/nitrictech/go-sdk/handler"
1312
"github.com/nitrictech/go-sdk/nitric"
1413
)
1514

src/pages/reference/go/schedule/schedule-every.mdx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Sets the frequency and one or many handlers to be triggered.
99
import (
1010
"fmt"
1111

12-
"github.com/nitrictech/go-sdk/handler"
1312
"github.com/nitrictech/go-sdk/nitric"
1413
)
1514

@@ -46,16 +45,13 @@ func main() {
4645
import (
4746
"fmt"
4847

49-
"github.com/nitrictech/go-sdk/handler"
5048
"github.com/nitrictech/go-sdk/nitric"
5149
)
5250

5351
func main() {
5452
// Create a schedule that runs every 3 minutes
55-
nitric.NewSchedule("send reminder").Every("3 minutes", func(ctx *handler.IntervalContext, _ handler.IntervalHandler) (*handler.IntervalContext, error) {
53+
nitric.NewSchedule("send reminder").Every("3 minutes", func() {
5654
// code which sends a reminder
57-
58-
return ctx, nil
5955
})
6056

6157
if err := nitric.Run(); err != nil {

src/pages/reference/go/schedule/schedule.mdx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ Creates a new Schedule to run a function on a defined frequency.
99
import (
1010
"fmt"
1111

12-
"github.com/nitrictech/go-sdk/handler"
1312
"github.com/nitrictech/go-sdk/nitric"
1413
)
1514

1615
func main() {
17-
nitric.NewSchedule("aggregate-data").Every("3 days", func(ctx *handler.IntervalContext, _ handler.IntervalHandler) (*handler.IntervalContext, error) {
16+
nitric.NewSchedule("aggregate-data").Every("3 days", func() {
1817
fmt.Println("aggregating data")
19-
20-
return ctx, nil
2118
})
2219

2320
if err := nitric.Run(); err != nil {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"context"
1111
"fmt"
1212

13-
"github.com/nitrictech/go-sdk/handler"
13+
"github.com/nitrictech/go-sdk/nitric/storage"
1414
"github.com/nitrictech/go-sdk/nitric"
1515
)
1616

@@ -22,15 +22,15 @@ func main() {
2222
return
2323
}
2424

25-
assets.On(handler.DeleteNotification, "*", func(ctx *handler.BlobEventContext) {
25+
assets.On(handler.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 *handler.BlobEventContext) {
29+
assets.On(handler.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 *handler.BlobEventContext) error {
33+
assets.On(handler.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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import (
4747
"context"
4848
"fmt"
4949

50-
"github.com/nitrictech/go-sdk/handler"
50+
"github.com/nitrictech/go-sdk/nitric/websockets"
5151
"github.com/nitrictech/go-sdk/nitric"
5252
)
5353

@@ -58,7 +58,7 @@ func main() {
5858
}
5959

6060
// Broadcast message to all the registered websocket connections
61-
ws.On(handler.WebsocketMessage, func(ctx *handler.WebsocketContext, next handler.WebsocketHandler) (*handler.WebsocketContext, error) {
61+
ws.On(handler.WebsocketMessage, 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-send.mdx

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import (
5555
"context"
5656
"fmt"
5757

58-
"github.com/nitrictech/go-sdk/handler"
58+
"github.com/nitrictech/go-sdk/nitric/websockets"
5959
"github.com/nitrictech/go-sdk/nitric"
6060
)
6161

@@ -71,32 +71,22 @@ func main() {
7171
}
7272

7373
// Register a new connection on connect
74-
ws.On(handler.WebsocketConnect, func(ctx *handler.WebsocketContext, next handler.WebsocketHandler) (*handler.WebsocketContext, error) {
75-
err := connections.Set(context.TODO(), ctx.Request.ConnectionID(), map[string]interface{}{
74+
ws.On(handler.WebsocketConnect, func(ctx *websockets.Ctx) error {
75+
return connections.Set(context.TODO(), ctx.Request.ConnectionID(), map[string]interface{}{
7676
"connectionId": ctx.Request.ConnectionID(),
7777
})
78-
if err != nil {
79-
return ctx, err
80-
}
81-
82-
return next(ctx)
8378
})
8479

8580
// Remove a registered connection on disconnect
86-
ws.On(handler.WebsocketDisconnect, func(ctx *handler.WebsocketContext, next handler.WebsocketHandler) (*handler.WebsocketContext, error) {
87-
err := connections.Delete(context.TODO(), ctx.Request.ConnectionID())
88-
if err != nil {
89-
return ctx, err
90-
}
91-
92-
return next(ctx)
81+
ws.On(handler.WebsocketDisconnect, func(ctx *websockets.Ctx) error {
82+
return connections.Delete(context.TODO(), ctx.Request.ConnectionID())
9383
})
9484

9585
// Broadcast message to all the registered websocket connections
96-
ws.On(handler.WebsocketMessage, func(ctx *handler.WebsocketContext, next handler.WebsocketHandler) (*handler.WebsocketContext, error) {
86+
ws.On(handler.WebsocketMessage, func(ctx *websockets.Ctx) error {
9787
connectionStream, err := connections.Keys(context.TODO())
9888
if err != nil {
99-
return ctx, err
89+
return err
10090
}
10191

10292
for {
@@ -107,11 +97,11 @@ func main() {
10797

10898
err = ws.Send(context.TODO(), connectionId, []byte(ctx.Request.Message()))
10999
if err != nil {
110-
return ctx, err
100+
return err
111101
}
112102
}
113103

114-
return next(ctx)
104+
return nil
115105
})
116106

117107
if err := nitric.Run(); err != nil {

0 commit comments

Comments
 (0)