-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.go
59 lines (48 loc) · 1.02 KB
/
client.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
56
57
58
59
package openlineage
import (
"context"
"fmt"
"os"
"github.com/ThijsKoot/openlineage-go/pkg/transport"
)
var DefaultClient, _ = NewClient(ClientConfig{
Transport: transport.Config{
Type: transport.TransportTypeConsole,
Console: &transport.ConsoleConfig{
PrettyPrint: true,
},
},
})
func NewClient(cfg ClientConfig) (*Client, error) {
if cfg.Disabled || os.Getenv("OPENLINEAGE_DISABLED") != "" {
return &Client{
disabled: true,
}, nil
}
transport, err := transport.New(cfg.Transport)
if err != nil {
return nil, fmt.Errorf("create transport: %w", err)
}
namespace := cfg.Namespace
if cfg.Namespace == "" {
namespace = "default"
}
return &Client{
transport: transport,
Namespace: namespace,
}, nil
}
type Client struct {
disabled bool
transport transport.Transport
Namespace string
}
type Emittable interface {
AsEmittable() Event
}
func (olc *Client) Emit(ctx context.Context, event Emittable) error {
if olc.disabled {
return nil
}
return olc.transport.Emit(ctx, event.AsEmittable())
}