-
Notifications
You must be signed in to change notification settings - Fork 41
/
workflow.go
57 lines (47 loc) · 1.7 KB
/
workflow.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
package httpclient
import (
"context"
"net/http"
"github.com/fission/fission-workflows/pkg/apiserver"
"github.com/fission/fission-workflows/pkg/types"
)
type WorkflowAPI struct {
baseAPI
}
func NewWorkflowAPI(endpoint string, client http.Client) *WorkflowAPI {
return &WorkflowAPI{
baseAPI: baseAPI{
endpoint: endpoint,
client: client,
},
}
}
func (api *WorkflowAPI) Create(ctx context.Context, spec *types.WorkflowSpec) (*types.ObjectMetadata, error) {
result := &types.ObjectMetadata{}
err := callWithJSON(ctx, http.MethodPost, api.formatURL("/workflow"), spec, result)
return result, err
}
func (api *WorkflowAPI) CreateSync(ctx context.Context, spec *types.WorkflowSpec) (*types.Workflow, error) {
wf := &types.Workflow{}
err := callWithJSON(ctx, http.MethodPost, api.formatURL("/workflow/sync"), spec, wf)
return wf, err
}
func (api *WorkflowAPI) List(ctx context.Context) (*apiserver.WorkflowList, error) {
result := &apiserver.WorkflowList{}
err := callWithJSON(ctx, http.MethodGet, api.formatURL("/workflow"), nil, result)
return result, err
}
func (api *WorkflowAPI) Get(ctx context.Context, id string) (*types.Workflow, error) {
result := &types.Workflow{}
err := callWithJSON(ctx, http.MethodGet, api.formatURL("/workflow/"+id), nil, result)
return result, err
}
func (api *WorkflowAPI) Delete(ctx context.Context, id string) error {
err := callWithJSON(ctx, http.MethodDelete, api.formatURL("/workflow/"+id), nil, nil)
return err
}
func (api *WorkflowAPI) Events(ctx context.Context, id string) (*apiserver.ObjectEvents, error) {
result := &apiserver.ObjectEvents{}
err := callWithJSON(ctx, http.MethodGet, api.formatURL("/workflow/"+id+"/events"), nil, result)
return result, err
}