Skip to content

Commit

Permalink
fix json request response
Browse files Browse the repository at this point in the history
  • Loading branch information
apinonformoso committed Feb 26, 2025
1 parent 8a2012e commit f7948bb
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions partner_interconnect_attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package godo

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
Expand Down Expand Up @@ -60,7 +61,7 @@ type partnerInterconnectAttachmentRequestBody struct {
// VPCIDs is the IDs of the VPCs to which the Partner Interconnect Attachment is connected
VPCIDs []string `json:"vpc_ids,omitempty"`
// BGP is the BGP configuration of the Partner Interconnect Attachment
BGP *BGP `json:"bgp,omitempty"`
BGP *BGPInput `json:"bgp,omitempty"`
}

func (req *PartnerInterconnectAttachmentCreateRequest) buildReq() *partnerInterconnectAttachmentRequestBody {
Expand All @@ -73,7 +74,13 @@ func (req *PartnerInterconnectAttachmentCreateRequest) buildReq() *partnerInterc
}

if req.BGP != (BGP{}) {
request.BGP = &req.BGP
request.BGP = &BGPInput{
LocalASN: req.BGP.LocalASN,
LocalRouterIP: req.BGP.LocalRouterIP,
PeerASN: req.BGP.PeerASN,
PeerRouterIP: req.BGP.PeerRouterIP,
AuthKey: req.BGP.AuthKey,
}
}

return request
Expand All @@ -99,6 +106,49 @@ type BGP struct {
// LocalRouterIP is the local router IP
LocalRouterIP string `json:"local_router_ip,omitempty"`
// PeerASN is the peer ASN
PeerASN int `json:"peer_asn,omitempty"`
// PeerRouterIP is the peer router IP
PeerRouterIP string `json:"peer_router_ip,omitempty"`
// AuthKey is the authentication key
AuthKey string `json:"auth_key,omitempty"`
}

func (b *BGP) UnmarshalJSON(data []byte) error {
type Alias BGP
aux := &struct {
LocalASN *int `json:"local_asn,omitempty"`
LocalRouterASN *int `json:"local_router_asn,omitempty"`
PeerASN *int `json:"peer_asn,omitempty"`
PeerRouterASN *int `json:"peer_router_asn,omitempty"`
*Alias
}{
Alias: (*Alias)(b),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}

if aux.LocalASN != nil {
b.LocalASN = *aux.LocalASN
} else if aux.LocalRouterASN != nil {
b.LocalASN = *aux.LocalRouterASN
}

if aux.PeerASN != nil {
b.PeerASN = *aux.PeerASN
} else if aux.PeerRouterASN != nil {
b.PeerASN = *aux.PeerRouterASN
}
return nil
}

// BGPInput represents the BGP configuration of a Partner Interconnect Attachment.
type BGPInput struct {
// LocalASN is the local ASN
LocalASN int `json:"local_router_asn,omitempty"`
// LocalRouterIP is the local router IP
LocalRouterIP string `json:"local_router_ip,omitempty"`
// PeerASN is the peer ASN
PeerASN int `json:"peer_router_asn,omitempty"`
// PeerRouterIP is the peer router IP
PeerRouterIP string `json:"peer_router_ip,omitempty"`
Expand Down

0 comments on commit f7948bb

Please sign in to comment.