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

Commit fdfeb68

Browse files
jyecuschdavemooreuws
authored andcommitted
new Go sdk docs
1 parent 071625e commit fdfeb68

File tree

106 files changed

+1330
-3383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1330
-3383
lines changed

src/pages/apis.mdx

Lines changed: 121 additions & 204 deletions
Large diffs are not rendered by default.

src/pages/guides/go/serverless-rest-api-example.mdx

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,32 +82,17 @@ If everything is working as expected you can now delete all files/folders in the
8282
Let's begin by setting up the Profiles API. First, create a new folder called `profiles` within the services directory. Inside this folder, add a file named `main.go`, and include the following code:
8383

8484
```go
85-
package main
86-
8785
import (
88-
"context"
89-
"encoding/json"
90-
"fmt"
91-
92-
"github.com/google/uuid"
93-
"github.com/nitrictech/go-sdk/nitric/apis"
94-
"github.com/nitrictech/go-sdk/nitric"
86+
"github.com/nitrictech/go-sdk/nitric"
87+
"github.com/nitrictech/go-sdk/nitric/keyvalue"
9588
)
9689

9790
func main() {
98-
profilesApi, err := nitric.NewApi("public")
99-
if err != nil {
100-
return
101-
}
91+
profilesApi := nitric.NewApi("public")
10292

103-
profiles, err := nitric.NewKv("profiles").Allow(nitric.KvStoreGet, nitric.KvStoreSet)
104-
if err != nil {
105-
return
106-
}
93+
profiles := nitric.NewKv("profiles").Allow(keyvalue.KvStoreGet, keyvalue.KvStoreSet)
10794

108-
if err := nitric.Run(); err != nil {
109-
fmt.Println(err)
110-
}
95+
nitric.Run()
11196
}
11297
```
11398

@@ -142,6 +127,7 @@ profilesApi.Post("/profiles", func(ctx *apis.Ctx) error {
142127
}
143128

144129
ctx.Response.Body = []byte(id)
130+
return nil
145131
})
146132
```
147133

@@ -176,7 +162,7 @@ profilesApi.Get("/profiles", func(ctx *apis.Ctx) error {
176162
for {
177163
key, err := keys.Recv()
178164
if err != nil {
179-
return err
165+
break
180166
}
181167
content, _ := profiles.Get(context.Background(), key)
182168
profileContent = append(profileContent, content)
@@ -297,11 +283,7 @@ If you want to go a bit deeper and create some other resources with Nitric, why
297283
Define a bucket named `profileImages` with read/write permissions
298284

299285
```go
300-
profileImages, err := nitric.NewBucket("profileImages").Allow(nitric.BucketRead, nitric.BucketWrite)
301-
if err != nil {
302-
fmt.Println(err)
303-
return
304-
}
286+
profileImages := nitric.NewBucket("profileImages").Allow(storage.BucketRead, storage.BucketWrite)
305287
```
306288

307289
### Get a URL to upload a profile image
@@ -311,7 +293,7 @@ profilesApi.Get("/profiles/:id/image/upload", func(ctx *apis.Ctx) error {
311293
id := ctx.Request.PathParams()["id"]
312294
photoId := fmt.Sprintf("images/%s/photo.png", id)
313295

314-
photoUrl, err := profileImages.File(photoId).UploadUrl(context.TODO(), 600)
296+
photoUrl, err := profileImages.UploadUrl(context.TODO(), photoId, storage.WithPresignUrlExpiry(600))
315297
if err != nil {
316298
return err
317299
}
@@ -329,7 +311,7 @@ profilesApi.Get("/profiles/:id/image/download", func(ctx *apis.Ctx) error {
329311
id := ctx.Request.PathParams()["id"]
330312
photoId := fmt.Sprintf("images/%s/photo.png", id)
331313

332-
photoUrl, err := profileImages.File(photoId).DownloadUrl(context.TODO(), 600)
314+
photoUrl, err := profileImages.DownloadUrl(context.TODO(), photoId, storage.WithPresignUrlExpiry(600))
333315
if err != nil {
334316
return err
335317
}
@@ -347,7 +329,7 @@ profilesApi.Get("/profiles/:id/image/view", func(ctx *apis.Ctx) error {
347329
id := ctx.Request.PathParams()["id"]
348330
photoId := fmt.Sprintf("images/%s/photo.png", id)
349331

350-
photoUrl, err := profileImages.File(photoId).DownloadUrl(ctx.Request.Context(), 600)
332+
photoUrl, err := profileImages.DownloadUrl(context.TODO(), photoId, storage.WithPresignUrlExpiry(600))
351333
if err != nil {
352334
return err
353335
}

src/pages/keyvalue.mdx

Lines changed: 50 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,14 @@ Nitric.run()
5454

5555
```go
5656
import (
57-
"fmt"
58-
59-
"github.com/nitrictech/go-sdk/nitric"
57+
"github.com/nitrictech/go-sdk/nitric"
58+
"github.com/nitrictech/go-sdk/nitric/keyvalue"
6059
)
6160

6261
func main() {
63-
countries, err := nitric.NewKv("Countries").Allow(nitric.KvStoreGet, nitric.KvStoreSet, nitric.KvStoreDelete)
64-
if err != nil {
65-
fmt.Println(err)
66-
return
67-
}
68-
69-
if err := nitric.Run(); err != nil {
70-
fmt.Println(err)
71-
}
62+
countries := nitric.NewKv("Countries").Allow(keyvalue.KvStoreGet, keyvalue.KvStoreSet, keyvalue.KvStoreDelete)
63+
64+
nitric.Run()
7265
}
7366
```
7467

@@ -121,21 +114,21 @@ Nitric.run()
121114

122115
```go
123116
import (
124-
"context"
125-
"fmt"
117+
"context"
126118

127-
"github.com/nitrictech/go-sdk/nitric"
119+
"github.com/nitrictech/go-sdk/nitric"
120+
"github.com/nitrictech/go-sdk/nitric/keyvalue"
128121
)
129122

130-
countries, _ := nitric.NewKv("Countries").Allow(nitric.KvStoreSet)
123+
func main() {
124+
countries := nitric.NewKv("Countries").Allow(keyvalue.KvStoreSet)
131125

132-
_ = countries.Set(context.TODO(), "USA", map[string]interface{}{
133-
"name": "United States of America",
134-
"population": 329500000,
135-
})
126+
_ = countries.Set(context.TODO(), "USA", map[string]interface{}{
127+
"name": "United States of America",
128+
"population": 329500000,
129+
})
136130

137-
if err := nitric.Run(); err != nil {
138-
fmt.Println(err)
131+
nitric.Run()
139132
}
140133
```
141134

@@ -215,18 +208,18 @@ Nitric.run()
215208

216209
```go
217210
import (
218-
"context"
219-
"fmt"
211+
"context"
220212

221-
"github.com/nitrictech/go-sdk/nitric"
213+
"github.com/nitrictech/go-sdk/nitric"
214+
"github.com/nitrictech/go-sdk/nitric/keyvalue"
222215
)
223216

224-
countries, _ := nitric.NewKv("Countries").Allow(nitric.KvStoreGet)
217+
func main() {
218+
countries := nitric.NewKv("Countries").Allow(keyvalue.KvStoreGet)
225219

226-
country, _ := countries.Get(context.TODO(), "USA")
220+
country, _ := countries.Get(context.TODO(), "USA")
227221

228-
if err := nitric.Run(); err != nil {
229-
fmt.Println(err)
222+
nitric.Run()
230223
}
231224
```
232225

@@ -281,23 +274,23 @@ Nitric.run()
281274

282275
```go
283276
import (
284-
"context"
285-
"fmt"
277+
"context"
286278

287-
"github.com/nitrictech/go-sdk/nitric"
279+
"github.com/nitrictech/go-sdk/nitric"
280+
"github.com/nitrictech/go-sdk/nitric/keyvalue"
288281
)
289282

290-
countries, _ := nitric.NewKv("Countries").Allow(nitric.KvStoreSet, nitric.KvStoreDelete)
283+
func main() {
284+
countries := nitric.NewKv("Countries").Allow(keyvalue.KvStoreSet, keyvalue.KvStoreDelete)
291285

292-
_ = countries.Set(context.TODO(), "USA", map[string]interface{}{
293-
"name": "United States of America",
294-
"population": 329500000,
295-
})
286+
_ = countries.Set(context.TODO(), "USA", map[string]interface{}{
287+
"name": "United States of America",
288+
"population": 329500000,
289+
})
296290

297-
_ = countries.Delete(context.TODO(), "USA")
291+
_ = countries.Delete(context.TODO(), "USA")
298292

299-
if err := nitric.Run(); err != nil {
300-
fmt.Println(err)
293+
nitric.Run()
301294
}
302295
```
303296

@@ -351,28 +344,30 @@ Nitric.run()
351344

352345
```go
353346
import (
354-
"context"
355-
"fmt"
347+
"context"
348+
"fmt"
356349

357-
"github.com/nitrictech/go-sdk/nitric"
350+
"github.com/nitrictech/go-sdk/nitric"
351+
"github.com/nitrictech/go-sdk/nitric/keyvalue"
358352
)
359353

360-
countries, _ := nitric.NewKv("Countries").Allow(nitric.KvStoreGet)
354+
func main() {
361355

362-
keys, _ := profiles.Keys(context.TODO())
356+
countries := nitric.NewKv("Countries").Allow(keyvalue.KvStoreGet)
363357

364-
for {
365-
key, err := keys.Recv()
366-
if err != nil {
367-
// check if the stream has ended
368-
break
369-
}
358+
keys, _ := countries.Keys(context.TODO())
370359

371-
fmt.Println(key)
372-
}
360+
for {
361+
key, err := keys.Recv()
362+
if err != nil {
363+
// check if the stream has ended
364+
break
365+
}
366+
367+
fmt.Println(key)
368+
}
373369

374-
if err := nitric.Run(); err != nil {
375-
fmt.Println(err)
370+
nitric.Run()
376371
}
377372
```
378373

0 commit comments

Comments
 (0)