Skip to content

Commit

Permalink
feat: support adding connect metadata (#13)
Browse files Browse the repository at this point in the history
* feature connect metadata

* fix import
  • Loading branch information
Patrick0308 authored Jul 11, 2024
1 parent ca993be commit a0bf23b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
9 changes: 6 additions & 3 deletions go/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

protocol "github.com/longportapp/openapi-protocol/go"

control "github.com/longportapp/openapi-protobufs/gen/go/control"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -104,8 +105,9 @@ type client struct {
reconnectCount int
doReconnectting bool

addr *url.URL
dialOptions *DialOptions
addr *url.URL
dialOptions *DialOptions
connectMetadata map[string]string
}

// Dial using to dial with server
Expand Down Expand Up @@ -181,7 +183,7 @@ func (c *client) auth() error {
}
res, err := c.Do(context.Background(), &Request{
Cmd: uint32(control.Command_CMD_AUTH),
Body: &control.AuthRequest{Token: token},
Body: &control.AuthRequest{Token: token, Metadata: c.connectMetadata},
}, RequestTimeout(c.dialOptions.AuthTimeout))

if err != nil {
Expand Down Expand Up @@ -294,6 +296,7 @@ func (c *client) reconnect() error {
func (c *client) reconnectDial() error {
res, err := c.Do(c.Context, &Request{Cmd: uint32(control.Command_CMD_RECONNECT), Body: &control.ReconnectRequest{
SessionId: c.authInfo.SessionId,
Metadata: c.connectMetadata,
}}, RequestTimeout(c.dialOptions.AuthTimeout))

if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions go/client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,10 @@ func WithLogger(l protocol.Logger) ClientOption {
c.Logger = l
}
}

// WithConnectMetadata set connect metadata
func WithConnectMetadata(m map[string]string) ClientOption {
return func(c *client) {
c.connectMetadata = m
}
}
2 changes: 1 addition & 1 deletion go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/golang/protobuf v1.5.2
github.com/gorilla/websocket v1.5.0
github.com/longbridgeapp/assert v0.1.0
github.com/longportapp/openapi-protobufs/gen/go v0.2.1
github.com/longportapp/openapi-protobufs/gen/go v0.4.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
google.golang.org/protobuf v1.28.1
Expand Down
4 changes: 2 additions & 2 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/longbridgeapp/assert v0.1.0 h1:KkQlHUJSpuUFkUDjwBJgghFl31+wwSDHTq/WRrvLjko=
github.com/longbridgeapp/assert v0.1.0/go.mod h1:ew3umReliXtk1bBG4weVURxdvR0tsN+rCEfjnA4YfxI=
github.com/longportapp/openapi-protobufs/gen/go v0.2.1 h1:AaubbUBGkawGYR4+XMorOIHr9Drte2CZBwjEKp6C1mU=
github.com/longportapp/openapi-protobufs/gen/go v0.2.1/go.mod h1:/chiEwEW4CnOVgKTaCf8rQUwes00Ku8q1CvRpOueWfo=
github.com/longportapp/openapi-protobufs/gen/go v0.4.0 h1:+wD5sq/DZS7HCUL6nOe7v7nNuM1EvuEDluk69f2+2nM=
github.com/longportapp/openapi-protobufs/gen/go v0.4.0/go.mod h1:/chiEwEW4CnOVgKTaCf8rQUwes00Ku8q1CvRpOueWfo=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down

0 comments on commit a0bf23b

Please sign in to comment.