-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema_service.go
55 lines (44 loc) · 1.2 KB
/
schema_service.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package danube
import (
"context"
"errors"
"github.com/danrusei/danube-go/proto" // Path to your generated proto package
)
// SchemaService is used to interact with the schema service
type schemaService struct {
cnxManager *connectionManager
requestID uint64
}
// NewSchemaService creates a new instance of SchemaService
func newSchemaService(cnxManager *connectionManager) *schemaService {
return &schemaService{
cnxManager: cnxManager,
requestID: 0,
}
}
// GetSchema retrieves the schema for the given topic
func (ss *schemaService) getSchema(ctx context.Context, addr string, topic string) (*Schema, error) {
conn, err := ss.cnxManager.getConnection(addr, addr)
if err != nil {
return nil, err
}
client := proto.NewDiscoveryClient(conn.grpcConn)
schemaRequest := &proto.SchemaRequest{
RequestId: ss.requestID,
Topic: topic,
}
response, err := client.GetSchema(ctx, schemaRequest)
if err != nil {
return nil, err
}
schemaResponse := response.GetSchema()
if schemaResponse == nil {
return nil, errors.New("schema response is nil")
}
// Convert ProtoSchema to Schema
schema, err := FromProtoSchema(schemaResponse)
if err != nil {
return nil, err
}
return schema, nil
}