MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / New

Function New

plugins/destination/file/client/client.go:28–61  ·  view source on GitHub ↗
(_ context.Context, logger zerolog.Logger, s []byte, opts plugin.NewClientOptions)

Source from the content-addressed store, hash-verified

26}
27
28func New(_ context.Context, logger zerolog.Logger, s []byte, opts plugin.NewClientOptions) (plugin.Client, error) {
29 c := &Client{
30 logger: logger.With().Str("module", "file").Logger(),
31 }
32 if opts.NoConnection {
33 return c, nil
34 }
35
36 if err := json.Unmarshal(s, &c.spec); err != nil {
37 return nil, fmt.Errorf("failed to unmarshal file spec: %w", err)
38 }
39 if err := c.spec.Validate(); err != nil {
40 return nil, err
41 }
42 c.spec.SetDefaults()
43
44 filetypesClient, err := filetypes.NewClient(&c.spec.FileSpec)
45 if err != nil {
46 return nil, fmt.Errorf("failed to create filetypes client: %w", err)
47 }
48 c.Client = filetypesClient
49
50 c.writer, err = streamingbatchwriter.New(c,
51 streamingbatchwriter.WithBatchSizeRows(*c.spec.BatchSize),
52 streamingbatchwriter.WithBatchSizeBytes(*c.spec.BatchSizeBytes),
53 streamingbatchwriter.WithBatchTimeout(c.spec.BatchTimeout.Duration()),
54 streamingbatchwriter.WithLogger(c.logger),
55 )
56 if err != nil {
57 return nil, err
58 }
59
60 return c, nil
61}
62
63func (c *Client) Close(ctx context.Context) error {
64 return c.writer.Close(ctx)

Callers 1

testPluginCustomFunction · 0.70

Calls 4

ErrorfMethod · 0.80
LoggerMethod · 0.45
ValidateMethod · 0.45
SetDefaultsMethod · 0.45

Tested by 1

testPluginCustomFunction · 0.56