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.
decort-golang-sdk/pkg/cloudbroker/grid/list.go

64 lines
1.5 KiB

3 years ago
package grid
import (
"context"
"encoding/json"
"net/http"
2 years ago
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
3 years ago
)
2 years ago
// ListRequest struct to get list of locations
3 years ago
type ListRequest struct {
2 years ago
// Find by id grid
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name grid
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
2 years ago
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
3 years ago
// Page number
// Required: false
3 years ago
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
3 years ago
// Page size
// Required: false
3 years ago
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
3 years ago
}
2 years ago
// List gets list of all locations as a ListGrids struct
2 years ago
func (g Grid) List(ctx context.Context, req ListRequest) (*ListGrids, error) {
2 years ago
2 years ago
res, err := g.ListRaw(ctx, req)
3 years ago
if err != nil {
return nil, err
}
list := ListGrids{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
2 years ago
return &list, nil
3 years ago
}
2 years ago
// ListRaw gets list of all locations as an array of bytes
func (g Grid) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
2 years ago
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
2 years ago
url := "/cloudbroker/grid/list"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}