v1.12.9
This commit is contained in:
46
pkg/sdn/flips/get.go
Normal file
46
pkg/sdn/flips/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package flips
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
// ID of a floating IP
|
||||
// Required: true
|
||||
FloatingIPID string `url:"floating_ip_id" json:"floating_ip_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets a floating ip details as a RecordFloatingIP struct
|
||||
func (fi FloatingIPs) Get(ctx context.Context, req GetRequest) (*RecordFloatingIP, error) {
|
||||
res, err := fi.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordFloatingIP{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
|
||||
}
|
||||
|
||||
// GetRaw gets a floating ip details as an array of bytes
|
||||
func (fi FloatingIPs) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/floating_ip/get"
|
||||
|
||||
res, err := fi.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
Reference in New Issue
Block a user