Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit 9eb571b

Browse files
author
alan
committed
feature: add task update actions in client pkg of golang sdk
Signed-off-by: alan <[email protected]>
1 parent 9c2fced commit 9eb571b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

client/request.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ func (client *APIClient) post(ctx context.Context, path string, query url.Values
6666
return client.sendRequest(ctx, "POST", path, query, body, headers)
6767
}
6868

69+
func (client *APIClient) put(ctx context.Context, path string, query url.Values, obj interface{}, headers map[string][]string) (*Response, error) {
70+
body, err := objectToJSONStream(obj)
71+
if err != nil {
72+
return nil, err
73+
}
74+
75+
return client.sendRequest(ctx, "PUT", path, query, body, headers)
76+
}
77+
6978
func (client *APIClient) postRawData(ctx context.Context, path string, query url.Values, data io.Reader, headers map[string][]string) (*Response, error) {
7079
return client.sendRequest(ctx, "POST", path, query, data, headers)
7180
}

client/task_update.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright The Dragonfly Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package client
18+
19+
import (
20+
"context"
21+
22+
"github.com/dragonflyoss/Dragonfly/apis/types"
23+
)
24+
25+
// TaskUpdate updates a task in supernode.
26+
func (client *APIClient) TaskUpdate(ctx context.Context, id string, config *types.TaskUpdateRequest) error {
27+
resp, err := client.put(ctx, "/tasks/"+id, nil, config, nil)
28+
if err != nil {
29+
return err
30+
}
31+
32+
ensureCloseReader(resp)
33+
return nil
34+
}

0 commit comments

Comments
 (0)