Skip to content

Commit

Permalink
Merge pull request #1513
Browse files Browse the repository at this point in the history
Hello, World example in Go
  • Loading branch information
arpitbbhayani authored Feb 24, 2025
2 parents d78f6c4 + 80cfdc6 commit a328a49
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 6 deletions.
6 changes: 2 additions & 4 deletions examples/chatroom-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.2.4
github.com/charmbracelet/lipgloss v1.0.0
github.com/dicedb/dicedb-go v1.0.1
github.com/dicedb/dicedb-go v1.0.2
)

require (
Expand All @@ -27,7 +27,5 @@ require (
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.3.8 // indirect
google.golang.org/protobuf v1.36.4 // indirect
google.golang.org/protobuf v1.36.5 // indirect
)

replace github.com/dicedb/dicedb-go => ../../../dicedb-go
6 changes: 4 additions & 2 deletions examples/chatroom-go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/charmbracelet/x/ansi v0.4.5 h1:LqK4vwBNaXw2AyGIICa5/29Sbdq58GbGdFngSe
github.com/charmbracelet/x/ansi v0.4.5/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/dicedb/dicedb-go v1.0.2 h1:mq9DN7RlblKlhrdcSAFf1xqpVzAARsSPWHZ5REqilJ0=
github.com/dicedb/dicedb-go v1.0.2/go.mod h1:pnhUYgUCPAtPycvuThbv3O6RXxVf5y8ZmDxQ8vyiXk0=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
Expand Down Expand Up @@ -47,5 +49,5 @@ golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
19 changes: 19 additions & 0 deletions examples/hello-world-go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Hello, World - DiceDB with Go
===

This is a simple Hello, World application with DiceDB using Go SDK.
The example, sets a key `k1` with value `v1` and then fetches
the key `k1` to get the value `v1`.

Before you run this example, please make sure you have installed
DiceDB and are running it locally.

> If not, you can change the connection parameters in the code
> and make your code point to some remote running instance of
> DiceDB
To run the example, execute the following command from this directory

```bash
$ go run main.go
```
10 changes: 10 additions & 0 deletions examples/hello-world-go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module hello-world-go

go 1.23.5

require github.com/dicedb/dicedb-go v1.0.2

require (
github.com/google/uuid v1.6.0 // indirect
google.golang.org/protobuf v1.36.4 // indirect
)
10 changes: 10 additions & 0 deletions examples/hello-world-go/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/dicedb/dicedb-go v1.0.2 h1:mq9DN7RlblKlhrdcSAFf1xqpVzAARsSPWHZ5REqilJ0=
github.com/dicedb/dicedb-go v1.0.2/go.mod h1:pnhUYgUCPAtPycvuThbv3O6RXxVf5y8ZmDxQ8vyiXk0=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
44 changes: 44 additions & 0 deletions examples/hello-world-go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"fmt"

"github.com/dicedb/dicedb-go"
"github.com/dicedb/dicedb-go/wire"
)

func main() {
// create a new DiceDB client and connect to the server
client, err := dicedb.NewClient("localhost", 7379)
if err != nil {
panic(err)
}
defer client.Close()

// define a key and value
key := "k1"
value := "v1"

// set the key and value
resp := client.Fire(&wire.Command{
Cmd: "SET",
Args: []string{key, value},
})
if resp.Err != "" {
fmt.Println("error setting key:", resp.Err)
return
}
fmt.Printf("successfully set key %s=%s\n", key, value)

// get the key and value
resp = client.Fire(&wire.Command{
Cmd: "GET",
Args: []string{key},
})
if resp.Err != "" {
fmt.Println("error getting key:", resp.Err)
return
}

fmt.Printf("successfully got key %s=%s\n", key, resp.GetVStr())
}

0 comments on commit a328a49

Please sign in to comment.