Skip to content

Commit

Permalink
chore: Added examples and manifest. (#4)
Browse files Browse the repository at this point in the history
* chore: Added examples and manifest.

* chore: Added repo to examples' headers.

* Fix sample snippets

* Document purpose of manifest

* Add missing newline

* Fix linter command

* Change examples structure

Co-authored-by: Andrey Pechkurov <[email protected]>
  • Loading branch information
amunra and puzpuzpuz authored Aug 15, 2022
1 parent 41ae846 commit 2d927fc
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
20 changes: 20 additions & 0 deletions examples.manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# manifest file lets questdb.io find the examples and lets Cloud docs
# substitute host/port and auth keys when auto-generating examples
- name: ilp
lang: go
path: examples/basic/main.go
header: |-
Go client library [docs](https://pkg.go.dev/github.com/questdb/go-questdb-client)
and [repo](https://github.com/questdb/go-questdb-client).
- name: ilp-auth-tls
lang: go
path: examples/auth-and-tls/main.go
header: |-
Go client library [docs](https://pkg.go.dev/github.com/questdb/go-questdb-client)
and [repo](https://github.com/questdb/go-questdb-client).
auth:
kid: testUser1
d: 5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48
addr:
host: localhost
port: 9009
48 changes: 48 additions & 0 deletions examples/auth-and-tls/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"context"
"log"
"time"

qdb "github.com/questdb/go-questdb-client"
)

func main() {
ctx := context.TODO()
sender, err := qdb.NewLineSender(
ctx,
qdb.WithAddress("localhost:9009"),
qdb.WithAuth(
"testUser1",
"5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48"),
qdb.WithTls(),
)
if err != nil {
log.Fatal(err)
}
// Make sure to close the sender on exit to release resources.
defer sender.Close()
// Send a few ILP messages.
err = sender.
Table("trades").
Symbol("name", "test_ilp1").
Float64Column("value", 12.4).
At(ctx, time.Now().UnixNano())
if err != nil {
log.Fatal(err)
}
err = sender.
Table("trades").
Symbol("name", "test_ilp2").
Float64Column("value", 11.4).
At(ctx, time.Now().UnixNano())
if err != nil {
log.Fatal(err)
}
// Make sure that the messages are sent over the network.
err = sender.Flush(ctx)
if err != nil {
log.Fatal(err)
}
}
42 changes: 42 additions & 0 deletions examples/basic/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"context"
"log"
"time"

qdb "github.com/questdb/go-questdb-client"
)

func main() {
ctx := context.TODO()
// Connect to QuestDB running on 127.0.0.1:9009
sender, err := qdb.NewLineSender(ctx)
if err != nil {
log.Fatal(err)
}
// Make sure to close the sender on exit to release resources.
defer sender.Close()
// Send a few ILP messages.
err = sender.
Table("trades").
Symbol("name", "test_ilp1").
Float64Column("value", 12.4).
At(ctx, time.Now().UnixNano())
if err != nil {
log.Fatal(err)
}
err = sender.
Table("trades").
Symbol("name", "test_ilp2").
Float64Column("value", 11.4).
At(ctx, time.Now().UnixNano())
if err != nil {
log.Fatal(err)
}
// Make sure that the messages are sent over the network.
err = sender.Flush(ctx)
if err != nil {
log.Fatal(err)
}
}

0 comments on commit 2d927fc

Please sign in to comment.