github.com/kjdelisle/consul@v1.4.5/agent/xds/response.go (about) 1 package xds 2 3 import ( 4 envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2" 5 envoycore "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" 6 "github.com/gogo/protobuf/proto" 7 "github.com/gogo/protobuf/types" 8 ) 9 10 func createResponse(typeURL string, version, nonce string, resources []proto.Message) (*envoy.DiscoveryResponse, error) { 11 anys := make([]types.Any, 0, len(resources)) 12 for _, r := range resources { 13 if r == nil { 14 continue 15 } 16 if any, ok := r.(*types.Any); ok { 17 anys = append(anys, *any) 18 continue 19 } 20 data, err := proto.Marshal(r) 21 if err != nil { 22 return nil, err 23 } 24 anys = append(anys, types.Any{ 25 TypeUrl: typeURL, 26 Value: data, 27 }) 28 } 29 resp := &envoy.DiscoveryResponse{ 30 VersionInfo: version, 31 Resources: anys, 32 TypeUrl: typeURL, 33 Nonce: nonce, 34 } 35 return resp, nil 36 } 37 38 func makeAddress(ip string, port int) envoycore.Address { 39 return envoycore.Address{ 40 Address: &envoycore.Address_SocketAddress{ 41 SocketAddress: &envoycore.SocketAddress{ 42 Address: ip, 43 PortSpecifier: &envoycore.SocketAddress_PortValue{ 44 PortValue: uint32(port), 45 }, 46 }, 47 }, 48 } 49 } 50 51 func makeAddressPtr(ip string, port int) *envoycore.Address { 52 a := makeAddress(ip, port) 53 return &a 54 }