-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintent_workflows.go
46 lines (39 loc) · 1.64 KB
/
intent_workflows.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 api
import (
"context"
"fmt"
"gopkg.in/nullstone-io/go-api-client.v0/response"
"gopkg.in/nullstone-io/go-api-client.v0/types"
"gopkg.in/nullstone-io/go-api-client.v0/ws"
"net/http"
)
type IntentWorkflows struct {
Client *Client
}
func (s IntentWorkflows) basePath(stackId, envId int64) string {
return fmt.Sprintf("/orgs/%s/stacks/%d/envs/%d/intent_workflows", s.Client.Config.OrgName, stackId, envId)
}
func (s IntentWorkflows) path(stackId, intentWorkflowId int64) string {
return fmt.Sprintf("/orgs/%s/stacks/%d/intent_workflows/%d", s.Client.Config.OrgName, stackId, intentWorkflowId)
}
func (s IntentWorkflows) List(ctx context.Context, stackId, envId int64) ([]types.IntentWorkflow, error) {
res, err := s.Client.Do(ctx, http.MethodGet, s.basePath(stackId, envId), nil, nil, nil)
if err != nil {
return nil, err
}
return response.ReadJsonVal[[]types.IntentWorkflow](res)
}
func (s IntentWorkflows) Get(ctx context.Context, stackId, intentWorkflowId int64) (*types.IntentWorkflow, error) {
res, err := s.Client.Do(ctx, http.MethodGet, s.path(stackId, intentWorkflowId), nil, nil, nil)
if err != nil {
return nil, err
}
return response.ReadJsonPtr[types.IntentWorkflow](res)
}
func (s IntentWorkflows) WatchGet(ctx context.Context, stackId, intentWorkflowId int64, retryFn ws.StreamerRetryFunc) (*types.IntentWorkflow, <-chan types.StreamObject[types.IntentWorkflowUpdate], error) {
endpoint, headers, err := s.Client.Config.ConstructWsEndpoint(ctx, s.path(stackId, intentWorkflowId))
if err != nil {
return nil, nil, err
}
return ws.StreamObject[types.IntentWorkflow, types.IntentWorkflowUpdate](ctx, endpoint, headers, retryFn)
}