Skip to content

Commit

Permalink
fix(client): keep Go 1.19 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
puzpuzpuz committed Mar 22, 2024
1 parent a1d913f commit 7f34fc5
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.20.x]
go-version: [1.19.x, 1.20.x]
name: Build with Go ${{ matrix.go-version }}
steps:
- name: Checkout repository
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Golang client for QuestDB's [Influx Line Protocol](https://questdb.io/docs/refer
(ILP) over HTTP and TCP. This library makes it easy to insert data into
[QuestDB](https://questdb.io).

The library requires Go 1.19 or newer.

Features:
* Context-aware API.
* Optimized for batch writes.
Expand Down
6 changes: 4 additions & 2 deletions examples/from-conf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
qdb "github.com/questdb/go-questdb-client/v3"
)

const dateOnly = "2006-01-02"

func main() {
ctx := context.TODO()
sender, err := qdb.LineSenderFromConf(ctx, "http::addr=localhost:9000;")
Expand All @@ -23,7 +25,7 @@ func main() {
}()

// Send a few ILP messages.
bday, err := time.Parse(time.DateOnly, "1856-07-10")
bday, err := time.Parse(dateOnly, "1856-07-10")
if err != nil {
log.Fatal(err)
}
Expand All @@ -38,7 +40,7 @@ func main() {
log.Fatal(err)
}

bday, err = time.Parse(time.DateOnly, "1847-02-11")
bday, err = time.Parse(dateOnly, "1847-02-11")
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 4 additions & 2 deletions examples/http/auth-and-tls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
qdb "github.com/questdb/go-questdb-client/v3"
)

const dateOnly = "2006-01-02"

func main() {
ctx := context.TODO()
sender, err := qdb.NewLineSender(
Expand All @@ -31,7 +33,7 @@ func main() {
}()

// Send a few ILP messages.
bday, err := time.Parse(time.DateOnly, "1856-07-10")
bday, err := time.Parse(dateOnly, "1856-07-10")
if err != nil {
log.Fatal(err)
}
Expand All @@ -46,7 +48,7 @@ func main() {
log.Fatal(err)
}

bday, err = time.Parse(time.DateOnly, "1847-02-11")
bday, err = time.Parse(dateOnly, "1847-02-11")
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 4 additions & 2 deletions examples/http/auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
qdb "github.com/questdb/go-questdb-client/v3"
)

const dateOnly = "2006-01-02"

func main() {
ctx := context.TODO()
sender, err := qdb.NewLineSender(
Expand All @@ -31,7 +33,7 @@ func main() {
}()

// Send a few ILP messages.
bday, err := time.Parse(time.DateOnly, "1856-07-10")
bday, err := time.Parse(dateOnly, "1856-07-10")
if err != nil {
log.Fatal(err)
}
Expand All @@ -46,7 +48,7 @@ func main() {
log.Fatal(err)
}

bday, err = time.Parse(time.DateOnly, "1847-02-11")
bday, err = time.Parse(dateOnly, "1847-02-11")
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 4 additions & 2 deletions examples/http/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
qdb "github.com/questdb/go-questdb-client/v3"
)

const dateOnly = "2006-01-02"

func main() {
ctx := context.TODO()
// Connect to QuestDB running on 127.0.0.1:9009
Expand All @@ -24,7 +26,7 @@ func main() {
}()

// Send a few ILP messages.
bday, err := time.Parse(time.DateOnly, "1856-07-10")
bday, err := time.Parse(dateOnly, "1856-07-10")
if err != nil {
log.Fatal(err)
}
Expand All @@ -39,7 +41,7 @@ func main() {
log.Fatal(err)
}

bday, err = time.Parse(time.DateOnly, "1847-02-11")
bday, err = time.Parse(dateOnly, "1847-02-11")
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 4 additions & 2 deletions examples/tcp/auth-and-tls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
qdb "github.com/questdb/go-questdb-client/v3"
)

const dateOnly = "2006-01-02"

func main() {
ctx := context.TODO()
sender, err := qdb.NewLineSender(
Expand All @@ -27,7 +29,7 @@ func main() {
defer sender.Close(ctx)

// Send a few ILP messages.
bday, err := time.Parse(time.DateOnly, "1856-07-10")
bday, err := time.Parse(dateOnly, "1856-07-10")
if err != nil {
log.Fatal(err)
}
Expand All @@ -42,7 +44,7 @@ func main() {
log.Fatal(err)
}

bday, err = time.Parse(time.DateOnly, "1847-02-11")
bday, err = time.Parse(dateOnly, "1847-02-11")
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 4 additions & 2 deletions examples/tcp/auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
qdb "github.com/questdb/go-questdb-client/v3"
)

const dateOnly = "2006-01-02"

func main() {
ctx := context.TODO()
sender, err := qdb.NewLineSender(
Expand All @@ -26,7 +28,7 @@ func main() {
defer sender.Close(ctx)

// Send a few ILP messages.
bday, err := time.Parse(time.DateOnly, "1856-07-10")
bday, err := time.Parse(dateOnly, "1856-07-10")
if err != nil {
log.Fatal(err)
}
Expand All @@ -41,7 +43,7 @@ func main() {
log.Fatal(err)
}

bday, err = time.Parse(time.DateOnly, "1847-02-11")
bday, err = time.Parse(dateOnly, "1847-02-11")
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 4 additions & 2 deletions examples/tcp/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
qdb "github.com/questdb/go-questdb-client/v3"
)

const dateOnly = "2006-01-02"

func main() {
ctx := context.TODO()
// Connect to QuestDB running on 127.0.0.1:9009
Expand All @@ -19,7 +21,7 @@ func main() {
defer sender.Close(ctx)

// Send a few ILP messages.
bday, err := time.Parse(time.DateOnly, "1856-07-10")
bday, err := time.Parse(dateOnly, "1856-07-10")
if err != nil {
log.Fatal(err)
}
Expand All @@ -34,7 +36,7 @@ func main() {
log.Fatal(err)
}

bday, err = time.Parse(time.DateOnly, "1847-02-11")
bday, err = time.Parse(dateOnly, "1847-02-11")
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/questdb/go-questdb-client/v3

go 1.18
go 1.19

require (
github.com/stretchr/testify v1.9.0
Expand Down
21 changes: 5 additions & 16 deletions tcp_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"bufio"
"context"
"crypto"
"crypto/ecdh"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
Expand Down Expand Up @@ -67,21 +66,11 @@ func newTcpLineSender(ctx context.Context, conf *lineSenderConfig) (*tcpLineSend
if err != nil {
return nil, fmt.Errorf("failed to decode auth key: %v", err)
}
// elliptic.P256().ScalarBaseMult is deprecated, so we use ecdh key
// and convert it to the ecdsa one.
ecdhKey, err := ecdh.P256().NewPrivateKey(rawKey)
if err != nil {
return nil, fmt.Errorf("invalid auth key: %v", err)
}
ecdhPubKey := ecdhKey.PublicKey().Bytes()
key = &ecdsa.PrivateKey{
PublicKey: ecdsa.PublicKey{
Curve: elliptic.P256(),
X: big.NewInt(0).SetBytes(ecdhPubKey[1:33]),
Y: big.NewInt(0).SetBytes(ecdhPubKey[33:]),
},
D: big.NewInt(0).SetBytes(ecdhKey.Bytes()),
}
// TODO(puzpuzpuz): migrate to crypto/ecdh one we don't need to support Go 1.19
key = new(ecdsa.PrivateKey)
key.PublicKey.Curve = elliptic.P256()
key.PublicKey.X, key.PublicKey.Y = key.PublicKey.Curve.ScalarBaseMult(rawKey)
key.D = new(big.Int).SetBytes(rawKey)
}

if conf.tlsMode == tlsDisabled {
Expand Down

0 comments on commit 7f34fc5

Please sign in to comment.