From 2d927fc0933d8a95afbd84d38ffffe31204443f7 Mon Sep 17 00:00:00 2001 From: amunra Date: Mon, 15 Aug 2022 17:04:58 +0100 Subject: [PATCH] chore: Added examples and manifest. (#4) * 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 --- examples.manifest.yaml | 20 +++++++++++++++ examples/auth-and-tls/main.go | 48 +++++++++++++++++++++++++++++++++++ examples/basic/main.go | 42 ++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 examples.manifest.yaml create mode 100644 examples/auth-and-tls/main.go create mode 100644 examples/basic/main.go diff --git a/examples.manifest.yaml b/examples.manifest.yaml new file mode 100644 index 0000000..33aad59 --- /dev/null +++ b/examples.manifest.yaml @@ -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 diff --git a/examples/auth-and-tls/main.go b/examples/auth-and-tls/main.go new file mode 100644 index 0000000..2ce1636 --- /dev/null +++ b/examples/auth-and-tls/main.go @@ -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) + } +} diff --git a/examples/basic/main.go b/examples/basic/main.go new file mode 100644 index 0000000..2a44327 --- /dev/null +++ b/examples/basic/main.go @@ -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) + } +}