Skip to content

Commit a2f9097

Browse files
feat(go): mongo db sample (#100)
* feat(go): mongo db sample * base readme update * format * Apply suggestions from code review Co-authored-by: norbjd <[email protected]> * review * oui * QueryEscape --------- Co-authored-by: norbjd <[email protected]>
1 parent a7a3b5f commit a2f9097

File tree

6 files changed

+262
-5
lines changed

6 files changed

+262
-5
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Table of Contents:
3030
<!-- markdownlint-disable MD033 -->
3131

3232
| Example | Runtime | Deployment |
33-
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|------------------------|
33+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ---------------------- |
3434
| **[Badge PHP](functions/badge-php/README.md)** <br/> A PHP function to generate repository badges. | php82 | [Serverless Framework] |
3535
| **[CORS Go](functions/cors-go/README.md)** <br/> A Go function which allows CORS requests. | go122 | [Serverless Framework] |
3636
| **[CORS Node](functions/cors-node/README.md)** <br/> A Node function which allows CORS requests. | node18 | [Serverless Framework] |
@@ -61,11 +61,12 @@ Table of Contents:
6161
| **[Serverless Gateway Python Example](functions/serverless-gateway-python/README.md)** <br/> A Python serverless API using Serverless Gateway. | python310 | [Python API Framework] |
6262
| **[Go and Transactional Email](functions/go-mail/README.md)** <br/> A Go function that send emails using Scaleway SDK. | go121 | [Serverless Framework] |
6363
| **[Rotate RDB Credentials](functions/secret-manager-rotate-secret/README.md)** <br/> A Go function that rotates RDB credentials stored in Secret Manager. | go120 | [Serverless Framework] |
64+
| **[Connect to Mongo DB](functions/go-mongo/)** <br/> A Go example to connect to Mongo DB | go124 | [Console] |
6465

6566
### 📦 Containers
6667

6768
| Example | Language | Deployment |
68-
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|------------------------|
69+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ---------------------- |
6970
| **[Container Bash Script](containers/bash-scheduled-job/README.md)** <br/> A Bash script runnning on a schedule using serverless containers. | Bash | [Serverless Framework] |
7071
| **[Function Handler Java](containers/function-handler-java/README.md)** <br/> A Java function handler deployed on CaaS. | Java | [Serverless Framework] |
7172
| **[NGINX CORS Private](containers/nginx-cors-private-python/README.md)** <br/> An NGINX proxy to allow CORS requests to a private container. | Python Flask | [Terraform] |
@@ -79,7 +80,7 @@ Table of Contents:
7980
### ⚙️ Jobs
8081

8182
| Example | Language | Deployment |
82-
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|-----------------------------|
83+
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | --------------------------- |
8384
| **[Serverless Jobs Hello World](jobs/terraform-hello-world/README.md)** <br/> An example of building a container image and running it as a Serverless Job using Terraform. | N/A | [Terraform]-[Console] |
8485
| **[Serverless MLOps](jobs/ml-ops/README.md)** <br/> An example of running a Serverless Machine Leaning workflow. | Python | [Terraform]-[Console]-[CLI] |
8586
| **[Auto Snapshot Instances](jobs/instances-snapshot/README.md)** <br/> Use Serverless Jobs to create snapshots of your instances | Go | [Console] |
@@ -90,15 +91,15 @@ Table of Contents:
9091
### 💬 Messaging and Queueing
9192

9293
| Example | Services | Language | Deployment |
93-
|--------------------------------------------------------------------------------------------------------------------------------------------------------|------------------|----------|-------------|
94+
| ------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------- | -------- | ----------- |
9495
| **[Manage large message](mnq/large-messages/README.md)** <br/> An example of infrastructure to manage large messages. | PaaS & S3 | Python | [Terraform] |
9596
| **[Serverless scraping](mnq/serverless-scraping/README.md)** <br/> An example of infrastructure to scrape the hackernews website. | PaaS & RDB | Python | [Terraform] |
9697
| **[SNS Instances Notification System](mnq/sns-instances-notification-system/README.md)** <br/> An example of infrastructure to use SNS with Instances. | PaaS & Instances | Golang | [Terraform] |
9798

9899
### 💜 Projects
99100

100101
| Example | Services | Language | Deployment |
101-
|-------------------------------------------------------------------------------------------------------------------------------------------|-------------|----------|------------------------|
102+
| ----------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -------- | ---------------------- |
102103
| **[Kong API Gateway](projects/kong-api-gateway/README.md)** <br/> Deploying a Kong Gateway on containers to provide routing to functions. | CaaS & FaaS | Python | [Serverless Framework] |
103104
| **[Serverless Gateway](https://github.com/scaleway/serverless-gateway)** <br/> Our serverless gateway for functions and containers. | API Gateway | Python | [Python API Framework] |
104105
| **[Monitoring Glaciers](projects/blogpost-glacier/README.md)** <br/> A project to monitor glaciers and the impact of global warming. | S3 & RDB | Golang | [Serverless Framework] |

functions/go-mongo/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Mongo + Go example
2+
3+
Example to demonstrate the possibility of connecting Serverless Functions to MongoDB.
4+
5+
For this example, [Scaleway Console](https://console.scaleway.com/) will be used for deployment.
6+
7+
> [!WARNING]
8+
> This is a basic sample that does not use a certificate for authentication, not recommended for production.
9+
10+
## Requirements
11+
12+
- MongoDB created [documentation](https://www.scaleway.com/en/docs/managed-mongodb-databases/quickstart/#how-to-create-a-database-instance)
13+
- The MongoDB instance must be public (not listening to a private network only since Serverless Functions do not support private networks yet)
14+
15+
## Step 1 - Mongo
16+
17+
After MongoDB creation, in the console, find the public endpoint of the database; it should look like: `<scw_database_id>.mgdb.<scw_region>.scw.cloud`
18+
19+
Once you get the endpoint, keep it somewhere for later use.
20+
21+
## Step 2 - Function Creation
22+
23+
Before creating the Function, we need to package it into a zip file.
24+
25+
> [!TIP]
26+
> It's recommended to do it via command line tools, so the following example shows how to zip this current folder:
27+
>
28+
> ```sh
29+
> cd ~/scaleway/serverless-examples/functions/go-mongo/
30+
> zip -r go-mongo.zip *
31+
> ```
32+
33+
- Create a Serverless Function namespace. [Documentation](https://www.scaleway.com/en/docs/serverless-functions/how-to/create-manage-delete-functions-namespace/#creating-a-serverless-functions-namespace)
34+
- In the created namespace, create a Serverless Function.
35+
- Select the latest Go runtime.
36+
- Upload the previously created `go-mongo.zip`.
37+
- Ensure the handler is `Handle`.
38+
- Add required Secrets to the Function:
39+
40+
| Key | Value |
41+
| --------------------- | -------------------------------------------------------------------------------------------------------------- |
42+
| MONGO_PUBLIC_ENDPOINT | (replace with required values): `<scw_database_id>.mgdb.<scw_region>.scw.cloud` |
43+
| MONGO_USER | user created during MongoDB setup |
44+
| MONGO_PASSWORD | password created during MongoDB user setup |
45+
46+
## Step 3 - Test
47+
48+
Once your Serverless Function is in `ready` state, you can call it using the generated endpoint.
49+
50+
Result should be similar to:
51+
52+
```json
53+
{ "ID": 2911126, "Name": "RandomName2911126" }
54+
```
55+
56+
## Local testing
57+
58+
For testing, you can use [Go Offline Testing](https://github.com/scaleway/serverless-functions-go).
59+
60+
To run locally, execute: `go run cmd/main.go`.

functions/go-mongo/cmd/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import (
4+
scw "github.com/scaleway/serverless-examples/functions/go-mongo"
5+
"github.com/scaleway/serverless-functions-go/local"
6+
)
7+
8+
// https://github.com/scaleway/serverless-functions-go
9+
func main() {
10+
// Replace "Handle" with your function handler name if necessary
11+
local.ServeHandler(scw.Handle, local.WithPort(8080))
12+
}

functions/go-mongo/go.mod

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module github.com/scaleway/serverless-examples/functions/go-mongo
2+
3+
go 1.24
4+
5+
require (
6+
github.com/scaleway/serverless-functions-go v0.1.2
7+
go.mongodb.org/mongo-driver v1.17.3
8+
)
9+
10+
require (
11+
github.com/golang/snappy v1.0.0 // indirect
12+
github.com/google/go-cmp v0.7.0 // indirect
13+
github.com/google/uuid v1.6.0 // indirect
14+
github.com/klauspost/compress v1.18.0 // indirect
15+
github.com/montanaflynn/stats v0.7.1 // indirect
16+
github.com/stretchr/testify v1.10.0 // indirect
17+
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
18+
github.com/xdg-go/scram v1.1.2 // indirect
19+
github.com/xdg-go/stringprep v1.0.4 // indirect
20+
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
21+
golang.org/x/crypto v0.38.0 // indirect
22+
golang.org/x/sync v0.14.0 // indirect
23+
golang.org/x/text v0.25.0 // indirect
24+
)

functions/go-mongo/go.sum

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
4+
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
5+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
6+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
7+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
8+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
9+
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
10+
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
11+
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
12+
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
13+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15+
github.com/scaleway/serverless-functions-go v0.1.2 h1:UUToB+XXpLDG9l6c9c0ALhAs1jvb6rV2Lkyj2kZEYCo=
16+
github.com/scaleway/serverless-functions-go v0.1.2/go.mod h1:23Hj74DYzTsVY3QgvsM0MGnx0+0OAAabTC06BOMJE58=
17+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
18+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
19+
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
20+
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
21+
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
22+
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
23+
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
24+
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
25+
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
26+
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
27+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
28+
go.mongodb.org/mongo-driver v1.17.3 h1:TQyXhnsWfWtgAhMtOgtYHMTkZIfBTpMTsMnd9ZBeHxQ=
29+
go.mongodb.org/mongo-driver v1.17.3/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
30+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
31+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
32+
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
33+
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
34+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
35+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
36+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
37+
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
38+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
39+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
40+
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
41+
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
42+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
43+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
44+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
45+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
46+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
47+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
48+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
49+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
50+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
51+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
52+
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
53+
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
54+
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
55+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
56+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
57+
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
58+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
59+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
60+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

functions/go-mongo/main.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package example
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"log/slog"
8+
"math/rand"
9+
"net/http"
10+
"net/url"
11+
"os"
12+
13+
"go.mongodb.org/mongo-driver/bson"
14+
"go.mongodb.org/mongo-driver/mongo"
15+
"go.mongodb.org/mongo-driver/mongo/options"
16+
)
17+
18+
// client is a global variable that holds the MongoDB client instance.
19+
var client *mongo.Client
20+
21+
// RandomDocument represents a document in the MongoDB collection with an ID and a Name.
22+
type RandomDocument struct {
23+
ID int `bson:"id"`
24+
Name string `bson:"name"`
25+
}
26+
27+
// init initializes the MongoDB client connection.
28+
// It reads the MongoDB connection details from environment variables and establishes a connection.
29+
func init() {
30+
mongoPublicEndpoint := os.Getenv("MONGO_PUBLIC_ENDPOINT")
31+
if mongoPublicEndpoint == "" {
32+
panic("MONGO_PUBLIC_ENDPOINT is required")
33+
}
34+
35+
mongoUser := os.Getenv("MONGO_USER")
36+
if mongoUser == "" {
37+
panic("MONGO_USER is required")
38+
}
39+
40+
mongoPassword := url.QueryEscape(os.Getenv("MONGO_PASSWORD"))
41+
if mongoPassword == "" {
42+
panic("MONGO_PASSWORD is required")
43+
}
44+
45+
// This is a basic sample that does not use certificate for authentication, not recommended for production.
46+
mongoURI := fmt.Sprintf(`mongodb+srv://%s:%s@%s/?tls=true&tlsInsecure=true`,
47+
mongoUser,
48+
mongoPassword,
49+
mongoPublicEndpoint)
50+
51+
var err error
52+
53+
client, err = mongo.Connect(context.TODO(), options.Client().ApplyURI(mongoURI))
54+
if err != nil {
55+
panic(err)
56+
}
57+
58+
err = client.Ping(context.TODO(), nil)
59+
if err != nil {
60+
panic(err)
61+
}
62+
63+
slog.Info("Connected to MongoDB")
64+
}
65+
66+
// Handle is an HTTP handler function that inserts a random document into the MongoDB collection
67+
// and returns the inserted document as a JSON response.
68+
func Handle(w http.ResponseWriter, _ *http.Request) {
69+
collection := client.Database("testdb").Collection("testcollection")
70+
71+
randomID := rand.Intn(100000000)
72+
73+
doc := RandomDocument{
74+
ID: randomID,
75+
Name: fmt.Sprintf("RandomName%d", randomID),
76+
}
77+
78+
insertResult, err := collection.InsertOne(context.TODO(), doc)
79+
if err != nil {
80+
http.Error(w, "Failed to insert document", http.StatusInternalServerError)
81+
return
82+
}
83+
84+
slog.Info("Inserted document", "id", insertResult.InsertedID)
85+
86+
var result RandomDocument
87+
88+
if err := collection.FindOne(context.TODO(), bson.M{"_id": insertResult.InsertedID}).Decode(&result); err != nil {
89+
http.Error(w, "Failed to find document", http.StatusInternalServerError)
90+
return
91+
}
92+
93+
slog.Info("Found document", "name", result.Name, "id", result.ID)
94+
95+
w.Header().Set("Content-Type", "application/json")
96+
97+
if err := json.NewEncoder(w).Encode(result); err != nil {
98+
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
99+
}
100+
}

0 commit comments

Comments
 (0)