You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
package extstorage
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/internal/constants"
|
|
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/internal/validators"
|
|
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/extstorage/models"
|
|
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/extstorage/requests"
|
|
)
|
|
|
|
// List gets a list of all storages.
|
|
func (e ExtStorage) List(ctx context.Context, req requests.ListExtStorageRequest) (*models.ListExtStorageResponse, error) {
|
|
|
|
res, err := e.ListRaw(ctx, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
list := models.ListExtStorageResponse{}
|
|
|
|
err = json.Unmarshal(res, &list)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &list, nil
|
|
}
|
|
|
|
// ListRaw gets a list of all storages as an array of bytes
|
|
func (e ExtStorage) ListRaw(ctx context.Context, req requests.ListExtStorageRequest) ([]byte, error) {
|
|
|
|
if err := validators.ValidateRequest(req); err != nil {
|
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := constants.APIv0 + "/external_storage"
|
|
|
|
res, err := e.client.ApiCall(ctx, http.MethodGet, url, req)
|
|
return res, err
|
|
}
|