Skip to content

Commit 50dd67e

Browse files
Merge pull request #1504 from gofr-dev/release/v1.34.0
Release/v1.34.0
2 parents d6cd85a + a264117 commit 50dd67e

Some content is hidden

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

88 files changed

+4926
-523
lines changed

Diff for: CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ docker run --name kafka-1 -p 9092:9092 \
8181
bitnami/kafka:3.4
8282
docker pull scylladb/scylla
8383
docker run --name scylla -d -p 2025:9042 scylladb/scylla
84+
docker run -d --name nats-server -p 4222:4222 -p 8222:8222 nats:latest -js
8485
docker pull surrealdb/surrealdb:latest
8586
docker run --name surrealdb -d -p 8000:8000 surrealdb/surrealdb:latest start --bind 0.0.0.0:8000
8687
docker run -d --name arangodb \

Diff for: docs/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ COPY docs/advanced-guide /app/src/app/docs/advanced-guide
88
COPY docs/references /app/src/app/docs/references
99
COPY docs/page.md /app/src/app/docs
1010
COPY docs/navigation.js /app/src/lib
11+
COPY docs/events.json /app/src/app/events
1112

1213
ENV NODE_ENV production
1314

Diff for: docs/advanced-guide/injecting-databases-drivers/page.md

+15
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,21 @@ added using the `app.AddArangoDB()` method, and users can use ArangoDB across th
958958

959959
```go
960960
type ArangoDB interface {
961+
// CreateDB creates a new database in ArangoDB.
962+
CreateDB(ctx context.Context, database string) error
963+
// DropDB deletes an existing database in ArangoDB.
964+
DropDB(ctx context.Context, database string) error
965+
966+
// CreateCollection creates a new collection in a database with specified type.
967+
CreateCollection(ctx context.Context, database, collection string, isEdge bool) error
968+
// DropCollection deletes an existing collection from a database.
969+
DropCollection(ctx context.Context, database, collection string) error
970+
971+
// CreateGraph creates a new graph in a database.
972+
CreateGraph(ctx context.Context, database, graph string, edgeDefinitions any) error
973+
// DropGraph deletes an existing graph from a database.
974+
DropGraph(ctx context.Context, database, graph string) error
975+
961976
// CreateDocument creates a new document in the specified collection.
962977
CreateDocument(ctx context.Context, dbName, collectionName string, document any) (string, error)
963978
// GetDocument retrieves a document by its ID from the specified collection.

Diff for: docs/advanced-guide/key-value-store/page.md

+130
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,133 @@ func Delete(ctx *gofr.Context) (any, error) {
8585
return fmt.Sprintf("Deleted Successfully key %v from Key-Value Store", "name"), nil
8686
}
8787
```
88+
## NATS-KV
89+
GoFr supports injecting NATS-KV that supports the above KVStore interface. Any driver that implements the interface can be added
90+
using `app.AddKVStore()` method, and user's can use NATS-KV across application with `gofr.Context`.
91+
92+
User's can easily inject a driver that supports this interface, this provides usability without
93+
compromising the extensibility to use multiple databases.
94+
95+
Import the gofr's external driver for NATS-KV:
96+
97+
```go
98+
go get gofr.dev/pkg/gofr/datasource/kv-store/nats
99+
```
100+
### Example
101+
```go
102+
package main
103+
104+
import (
105+
"encoding/json"
106+
"fmt"
107+
108+
"github.com/google/uuid"
109+
110+
"gofr.dev/pkg/gofr"
111+
"gofr.dev/pkg/gofr/datasource/kv-store/nats"
112+
"gofr.dev/pkg/gofr/http"
113+
)
114+
115+
type Person struct {
116+
ID string `json:"id,omitempty"`
117+
Name string `json:"name"`
118+
Age int `json:"age"`
119+
Email string `json:"email,omitempty"`
120+
}
121+
122+
func main() {
123+
app := gofr.New()
124+
125+
app.AddKVStore(nats.New(nats.Configs{
126+
Server: "nats://localhost:4222",
127+
Bucket: "persons",
128+
}))
129+
130+
app.POST("/person", CreatePerson)
131+
app.GET("/person/{id}", GetPerson)
132+
app.PUT("/person/{id}", UpdatePerson)
133+
app.DELETE("/person/{id}", DeletePerson)
134+
135+
app.Run()
136+
}
137+
138+
func CreatePerson(ctx *gofr.Context) (any, error) {
139+
var person Person
140+
if err := ctx.Bind(&person); err != nil {
141+
return nil, http.ErrorInvalidParam{Params: []string{"body"}}
142+
}
143+
144+
person.ID = uuid.New().String()
145+
personData, err := json.Marshal(person)
146+
if err != nil {
147+
return nil, fmt.Errorf("failed to serialize person")
148+
}
149+
150+
if err := ctx.KVStore.Set(ctx, person.ID, string(personData)); err != nil {
151+
return nil, err
152+
}
153+
154+
return person, nil
155+
}
156+
157+
func GetPerson(ctx *gofr.Context) (any, error) {
158+
id := ctx.PathParam("id")
159+
if id == "" {
160+
return nil, http.ErrorInvalidParam{Params: []string{"id"}}
161+
}
162+
163+
value, err := ctx.KVStore.Get(ctx, id)
164+
if err != nil {
165+
return nil, fmt.Errorf("person not found")
166+
}
167+
168+
var person Person
169+
if err := json.Unmarshal([]byte(value), &person); err != nil {
170+
return nil, fmt.Errorf("failed to parse person data")
171+
}
172+
173+
return person, nil
174+
}
175+
176+
func UpdatePerson(ctx *gofr.Context) (any, error) {
177+
id := ctx.PathParam("id")
178+
if id == "" {
179+
return nil, http.ErrorInvalidParam{Params: []string{"id"}}
180+
}
181+
182+
var person Person
183+
if err := ctx.Bind(&person); err != nil {
184+
return nil, http.ErrorInvalidParam{Params: []string{"body"}}
185+
}
186+
187+
person.ID = id
188+
personData, err := json.Marshal(person)
189+
if err != nil {
190+
return nil, fmt.Errorf("failed to serialize person")
191+
}
192+
193+
if err := ctx.KVStore.Set(ctx, id, string(personData)); err != nil {
194+
return nil, err
195+
}
196+
197+
return person, nil
198+
}
199+
200+
func DeletePerson(ctx *gofr.Context) (any, error) {
201+
id := ctx.PathParam("id")
202+
if id == "" {
203+
return nil, http.ErrorInvalidParam{Params: []string{"id"}}
204+
}
205+
206+
if err := ctx.KVStore.Delete(ctx, id); err != nil {
207+
return nil, fmt.Errorf("person not found")
208+
}
209+
210+
return map[string]string{"message": "Person deleted successfully"}, nil
211+
}
212+
```
213+
214+
215+
216+
217+

Diff for: docs/events.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"date": "23-24th November, 2024",
4+
"title": "GoFr Hackathon",
5+
"description": "GoFr Hackathon was a major success with participants building innovative solutions using the GoFr framework. It was an exciting two-day event where developers and tech enthusiasts came together to collaborate and create.",
6+
"imageSrc": "/events/hackathon.jpg"
7+
},
8+
{
9+
"date": "23-24th October, 2024",
10+
"title": "Open Source India",
11+
"description": "At Open Source India, we had an amazing experience connecting with the open-source community. The event featured various sessions, demos, and showcases on GoFr, highlighting its role in simplifying backend development and its microservice approach.",
12+
"imageSrc": "/events/OpenSourceIndia.jpeg"
13+
},
14+
{
15+
"date": "18-19th October, 2024",
16+
"title": "GopherCon Africa",
17+
"description": "At GopherCon Africa, GoFr stood out with its cutting-edge tools and integration features, making backend development easier. We showcased GoFr's capabilities in working with databases, observability tools, and its seamless HTTP/gRPC support.",
18+
"imageSrc": "/events/gopherconAfrica.jpeg"
19+
},
20+
{
21+
"date": "September 2024",
22+
"title": "GoFr Workshops",
23+
"description": "GoFr workshops are held regularly to engage with developers and tech enthusiasts. We’ve conducted workshops across multiple cities such as IIT BHU, IIIT Sri City, Thapar University, JIIT Noida, NIT Jalandhar, and NIT Nagpur offering hands-on experiences and deep dives into GoFr’s powerful features.",
24+
"imageSrc": "/events/WorkShop.jpeg"
25+
}
26+
]

Diff for: docs/public/events/OpenSourceIndia.jpeg

170 KB
Loading

Diff for: docs/public/events/WorkShop.jpeg

338 KB
Loading

Diff for: docs/public/events/gopherconAfrica.jpeg

352 KB
Loading

Diff for: docs/public/events/hackathon.jpg

445 KB
Loading

0 commit comments

Comments
 (0)