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.
48 lines
888 B
48 lines
888 B
package extnet
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
// Request struct for get detailed information about external network
|
|
type GetRequest struct {
|
|
// ID of external network
|
|
// Required: true
|
|
NetID uint64 `url:"net_id" json:"net_id"`
|
|
}
|
|
|
|
func (erq GetRequest) validate() error {
|
|
if erq.NetID == 0 {
|
|
return errors.New("validation-error: field NetID can not be empty or equal to 0")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Get gets detailed information about external network
|
|
func (e ExtNet) Get(ctx context.Context, req GetRequest) (*RecordExtNet, error) {
|
|
err := req.validate()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
url := "/cloudapi/extnet/get"
|
|
|
|
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
info := RecordExtNet{}
|
|
|
|
err = json.Unmarshal(res, &info)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &info, nil
|
|
}
|