v1.16.3
This commit is contained in:
@@ -2,6 +2,7 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -15,6 +16,11 @@ type EnableRequest struct {
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||
}
|
||||
|
||||
type asyncWrapperEnableRequest struct {
|
||||
EnableRequest
|
||||
AsyncMode bool `url:"asyncMode"`
|
||||
}
|
||||
|
||||
// Enable enables VINS by ID
|
||||
func (v VINS) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
@@ -24,7 +30,12 @@ func (v VINS) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
|
||||
url := "/cloudbroker/vins/enable"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
syncReq := asyncWrapperEnableRequest{
|
||||
EnableRequest: req,
|
||||
AsyncMode: false,
|
||||
}
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, syncReq)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -36,3 +47,32 @@ func (v VINS) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Enable enables VINS by ID in async mode
|
||||
func (v VINS) AsyncEnable(ctx context.Context, req EnableRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/enable"
|
||||
|
||||
asyncReq := asyncWrapperEnableRequest{
|
||||
EnableRequest: req,
|
||||
AsyncMode: true,
|
||||
}
|
||||
|
||||
result, err := v.client.DecortApiCall(ctx, http.MethodPost, url, asyncReq)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var resp string
|
||||
|
||||
err = json.Unmarshal(result, &resp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user