v1.16.3
This commit is contained in:
@@ -2,6 +2,7 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -69,6 +70,11 @@ type CreateInAccountRequest struct {
|
||||
EnableDefaultGateway interface{} `url:"enable_default_gateway,omitempty" json:"enable_default_gateway,omitempty" validate:"omitempty,isBool"`
|
||||
}
|
||||
|
||||
type asyncWrapperCreateInAccountRequest struct {
|
||||
CreateInAccountRequest
|
||||
AsyncMode bool `url:"asyncMode" json:"asyncMode"`
|
||||
}
|
||||
|
||||
// CreateInAccount creates VINS in account level
|
||||
func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
@@ -78,7 +84,12 @@ func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (
|
||||
|
||||
url := "/cloudapi/vins/createInAccount"
|
||||
|
||||
res, err := v.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||
syncReq := asyncWrapperCreateInAccountRequest{
|
||||
CreateInAccountRequest: req,
|
||||
AsyncMode: false,
|
||||
}
|
||||
|
||||
res, err := v.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, syncReq)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -90,3 +101,32 @@ func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CreateInAccount creates VINS in account level in async mode
|
||||
func (v VINS) AsyncCreateInAccount(ctx context.Context, req CreateInAccountRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
asyncReq := asyncWrapperCreateInAccountRequest{
|
||||
CreateInAccountRequest: req,
|
||||
AsyncMode: true,
|
||||
}
|
||||
|
||||
url := "/cloudapi/vins/createInAccount"
|
||||
|
||||
result, err := v.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, 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