-
Notifications
You must be signed in to change notification settings - Fork 3
/
create_connector.go
46 lines (38 loc) · 992 Bytes
/
create_connector.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
package connect
import (
"context"
"fmt"
)
type CreateConnectorRequest struct {
Name string `json:"name"`
Config map[string]interface{} `json:"config"`
}
func (c *CreateConnectorRequest) Validate() error {
if c.Name == "" {
return fmt.Errorf("connector name must be set")
}
if len(c.Config) == 0 {
return fmt.Errorf("connector config must be set")
}
return nil
}
func (c *Client) CreateConnector(ctx context.Context, req CreateConnectorRequest) (ConnectorInfo, error) {
if err := req.Validate(); err != nil {
return ConnectorInfo{}, fmt.Errorf("create connector options are invalid: %w", err)
}
var createResponse ConnectorInfo
response, err := c.client.NewRequest().
SetContext(ctx).
SetResult(&createResponse).
SetError(ApiError{}).
SetBody(req).
Post("/connectors")
if err != nil {
return ConnectorInfo{}, err
}
err = getErrorFromResponse(response)
if err != nil {
return ConnectorInfo{}, err
}
return createResponse, nil
}