forked from yandex-cloud/ydb-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
discovery.go
40 lines (35 loc) · 837 Bytes
/
discovery.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package ydb
import (
"context"
discovery "github.com/yandex-cloud/ydb-go-sdk/internal/api/grpc/Ydb_Discovery_V1"
"github.com/yandex-cloud/ydb-go-sdk/internal/api/protos/Ydb_Discovery"
)
type Endpoint struct {
Addr string
Port int
LoadFactor float32
}
type discoveryClient struct {
conn *conn
meta *meta
}
func (d *discoveryClient) Discover(ctx context.Context, database string) ([]Endpoint, error) {
var res Ydb_Discovery.ListEndpointsResult
req := Ydb_Discovery.ListEndpointsRequest{
Database: database,
}
err := (grpcCaller{
meta: d.meta,
}).call(ctx, d.conn, discovery.ListEndpoints, &req, &res)
if err != nil {
return nil, err
}
es := make([]Endpoint, len(res.Endpoints))
for i, e := range res.Endpoints {
es[i] = Endpoint{
Addr: e.Address,
Port: int(e.Port),
}
}
return es, nil
}