-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (36 loc) · 1015 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"time"
"github.com/Siddheshk02/NanoKV/kvstore"
"github.com/gofiber/fiber/v2"
)
func main() {
app := fiber.New()
kv := kvstore.NewKeyValueStore()
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("This is a Simple Key-Value store like Redis in Go.")
})
app.Get("/get/:key", func(c *fiber.Ctx) error {
key := c.Params("key")
value, ok := kv.Get(key)
if !ok {
return c.SendString("The Key " + key + " doesn't exist")
}
return c.SendString("The Key " + key + " has Value " + value)
})
app.Post("/set/:key/:value", func(c *fiber.Ctx) error {
key := c.Params("key")
value := c.Params("value")
kv.Set(key, value, 10*time.Minute)
return c.SendString("Key " + key + " Value " + value)
})
app.Delete("/delete/:key", func(c *fiber.Ctx) error {
key := c.Params("key")
ok := kv.Delete(key)
if !ok {
return c.SendString("The Key " + key + " doesn't exist")
}
return c.SendString("Successfully Deleted!!")
})
app.Listen(":3000")
}