v1.12.9
This commit is contained in:
51
pkg/sdn/routers/gwport/get.go
Normal file
51
pkg/sdn/routers/gwport/get.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package gwport
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get information about gateway port
|
||||
type GetRequest struct {
|
||||
// Router ID
|
||||
// Required: true
|
||||
RouterID string `url:"router_id" json:"router_id" validate:"required"`
|
||||
|
||||
// Gateway port ID
|
||||
// Required: true
|
||||
GatewayPortID string `url:"gateway_port_id" json:"gateway_port_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets gateway port details as a GatewayPort struct
|
||||
func (a GWPort) Get(ctx context.Context, req GetRequest) (*GatewayPort, error) {
|
||||
res, err := a.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := GatewayPort{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
|
||||
}
|
||||
|
||||
// GetRaw gets gateway port details as an array of bytes
|
||||
func (a GWPort) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/router/gateway_port/get"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
Reference in New Issue
Block a user