This commit is contained in:
dayterr
2026-09-15 17:23:58 +03:00
parent 71b53b743d
commit b39021820a
21 changed files with 692 additions and 105 deletions

View File

@@ -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 := "/cloudbroker/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 := "/cloudbroker/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
}