func (p BGPPeerConverter) ConvertAPIToKVPair(a unversioned.Resource) (*model.KVPair, error) {
	ap := a.(api.BGPPeer)
	k, err := p.ConvertMetadataToKey(ap.Metadata)
	if err != nil {
		return nil, err
	}
	d := model.KVPair{
		Key: k,
		Value: &model.BGPPeer{
			PeerIP: ap.Metadata.PeerIP,
			ASNum:  ap.Spec.ASNumber,
		},
	}
	return &d, nil
}
ConvertAPIToKVPair converts an API Policy structure to a KVPair containing a
backend BGPPeer and GlobalBGPPeerKey/HostBGPPeerKey.
package converter
import (
	api "github.com/projectcalico/libcalico-go/lib/apis/v1"
	"github.com/projectcalico/libcalico-go/lib/apis/v1/unversioned"
	"github.com/projectcalico/libcalico-go/lib/backend/model"
	"github.com/projectcalico/libcalico-go/lib/errors"
	"github.com/projectcalico/libcalico-go/lib/scope"
)
type BGPPeerConverter struct{}
func (p BGPPeerConverter) ConvertMetadataToKey(m unversioned.ResourceMetadata) (model.Key, error) {
	pm := m.(api.BGPPeerMetadata)
	if pm.Scope == scope.Global {
		return model.GlobalBGPPeerKey{
			PeerIP: pm.PeerIP,
		}, nil
	} else if pm.Scope == scope.Node {
		return model.NodeBGPPeerKey{
			PeerIP:   pm.PeerIP,
			Nodename: pm.Node,
		}, nil
	} else {
		return nil, errors.ErrorInsufficientIdentifiers{
			Name: "scope",
		}
	}
}