Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
feature: add task update actions in client pkg of golang sdk
Browse files Browse the repository at this point in the history
Signed-off-by: alan <[email protected]>
  • Loading branch information
zgfh committed Jul 31, 2019
1 parent 9c2fced commit 9eb571b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ func (client *APIClient) post(ctx context.Context, path string, query url.Values
return client.sendRequest(ctx, "POST", path, query, body, headers)
}

func (client *APIClient) put(ctx context.Context, path string, query url.Values, obj interface{}, headers map[string][]string) (*Response, error) {
body, err := objectToJSONStream(obj)
if err != nil {
return nil, err
}

return client.sendRequest(ctx, "PUT", path, query, body, headers)
}

func (client *APIClient) postRawData(ctx context.Context, path string, query url.Values, data io.Reader, headers map[string][]string) (*Response, error) {
return client.sendRequest(ctx, "POST", path, query, data, headers)
}
Expand Down
34 changes: 34 additions & 0 deletions client/task_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright The Dragonfly Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package client

import (
"context"

"github.com/dragonflyoss/Dragonfly/apis/types"
)

// TaskUpdate updates a task in supernode.
func (client *APIClient) TaskUpdate(ctx context.Context, id string, config *types.TaskUpdateRequest) error {
resp, err := client.put(ctx, "/tasks/"+id, nil, config, nil)
if err != nil {
return err
}

ensureCloseReader(resp)
return nil
}

0 comments on commit 9eb571b

Please sign in to comment.