// MakeThriftConcatEndpoint returns an endpoint that invokes the passed Thrift
// client. Useful only in clients, and only until a proper
// transport/thrift.Client exists.
426065
func MakeThriftConcatEndpoint(client *addthrift.AddServiceClient) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (interface{}, error) {
		req := request.(addendpoint.ConcatRequest)
		reply, err := client.Concat(ctx, req.A, req.B)
		return addendpoint.ConcatResponse{V: reply.Value, Err: err}, nil
	}
}
1095286
func Endpoint(BaseURL string) oauth2.Endpoint {
	return oauth2.Endpoint{
		TokenURL: TokenURL(BaseURL),
	}
}
1228504
func (e APIEndpoint) ToV1Endpoint(userAgent string, metaHeaders http.Header) *V1Endpoint {
	return newV1Endpoint(*e.URL, e.TLSConfig, userAgent, metaHeaders)
}
637007
func NewEndpoint(host string, port int, https bool, insecure bool, Cacert, cert, key []byte, timeout time.Duration) *Endpoint {
	endpoint := &Endpoint{
		Host:     host,
		Port:     port,
		HTTPS:    https,
		Insecure: insecure,
		CACert:   Cacert,
		Key:      key,
		Cert:     cert,
	}
	// if the timeout was set
	if timeout != 0 {
		endpoint.Timeout = timeout
	} else {
		// assign default 60sec timeout
		endpoint.Timeout = 60 * time.Second
	}

	return endpoint
}
946802
func MakeDeleteAddressEndpoint(s Service) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (response interface{}, err error) {
		req := request.(deleteAddressRequest)
		e := s.DeleteAddress(ctx, req.ProfileID, req.AddressID)
		return deleteAddressResponse{Err: e}, nil
	}
}
135913
func newExternalClusterClient(endpoint, token, caFilePath string) (*clientWrapper, error) {
	if endpoint == "" {
		return nil, errors.New("endpoint missing for external cluster client")
	}

	config := &rest.Config{
		Host:        endpoint,
		BearerToken: token,
	}

	if caFilePath != "" {
		caData, err := ioutil.ReadFile(caFilePath)
		if err != nil {
			return nil, fmt.Errorf("failed to read CA file %s: %s", caFilePath, err)
		}

		config.TLSClientConfig = rest.TLSClientConfig{CAData: caData}
	}
	return createClientFromConfig(config)
}
872094
func (p *Provider) Endpoint() oauth2.Endpoint {
	return oauth2.Endpoint{AuthURL: p.authURL, TokenURL: p.tokenURL}
}
835136
func (p *Provider) Endpoint() oauth2.Endpoint {
	return oauth2.Endpoint{AuthURL: p.AuthURL, TokenURL: p.TokenURL}
}
1317209
func (d *datapathHash) sumEndpoint(dp datapath.Datapath, epCfg datapath.EndpointConfiguration, staticData bool) (string, error) {
	result, err := d.Copy()
	if err != nil {
		return "", err
	}
	if staticData {
		dp.WriteEndpointConfig(result, epCfg)
	} else {
		dp.WriteTemplateConfig(result, epCfg)
	}
	return result.String(), nil
}
1303105
func PrimaryKeyToThrift(key *dosa.PrimaryKey) *dosarpc.PrimaryKey {
	ck := make([]*dosarpc.ClusteringKey, len(key.ClusteringKeys))
	for ckinx, clusteringKey := range key.ClusteringKeys {
		// TODO: The client uses 'descending' but the RPC uses 'ascending'? Fix this insanity!
		ascending := !clusteringKey.Descending
		name := clusteringKey.Name
		ck[ckinx] = &dosarpc.ClusteringKey{Name: &name, Asc: &ascending}
	}
	return &dosarpc.PrimaryKey{PartitionKeys: key.PartitionKeys, ClusteringKeys: ck}
}
994696
func (c *ServicedCli) createPublicEndpoints(ctx *cli.Context, services []service.Service,
	showVHosts bool, showPorts bool) ([]PublicEndpoint, error) {
	publicEndpoints := []PublicEndpoint{}

	// See if they provided the endpoint name
	epName := ""
	epFound := false
	if len(ctx.Args()) > 1 {
		epName = ctx.Args()[1]
	}

	// Iterate the list of services -> endpoints -> vhosts/ports
	for _, svc := range services {
		for _, ep := range svc.Endpoints {
			if epName != "" && epName != ep.Name {
				continue
			}
			epFound = true
			if showVHosts {
				for _, vhost := range ep.VHostList {
					publicEndpoint := NewPublicEndpoint(
						svc.Name,
						svc.ID,
						ep.Application,
						"vhost",
						"https",
						vhost.Name,
						vhost.Enabled,
					)
					publicEndpoints = append(publicEndpoints, publicEndpoint)
				}
			}
			if showPorts {
				for _, port := range ep.PortList {
					protocol := port.Protocol
					if protocol == "" {
						if port.UseTLS {
							protocol = "other-tls"
						} else {
							protocol = "other"
						}
					}
					publicEndpoint := NewPublicEndpoint(
						svc.Name,
						svc.ID,
						ep.Application,
						"port",
						protocol,
						port.PortAddr,
						port.Enabled,
					)
					publicEndpoints = append(publicEndpoints, publicEndpoint)
				}
			}
		}
	}

	if !epFound {
		return nil, fmt.Errorf("Endpoint '%s' not found", epName)
	}

	return publicEndpoints, nil
}
237819
func (l *listenContext) createConnectedEndpoint(s *segment, iss seqnum.Value, irs seqnum.Value, rcvdSynOpts *header.TCPSynOptions) (*endpoint, *tcpip.Error) {
	// Create a new endpoint.
	netProto := l.netProto
	if netProto == 0 {
		netProto = s.route.NetProto
	}
	n := newEndpoint(l.stack, netProto, nil)
	n.v6only = l.v6only
	n.id = s.id
	n.boundNICID = s.route.NICID()
	n.route = s.route.Clone()
	n.effectiveNetProtos = []tcpip.NetworkProtocolNumber{s.route.NetProto}
	n.rcvBufSize = int(l.rcvWnd)

	n.maybeEnableTimestamp(rcvdSynOpts)
	n.maybeEnableSACKPermitted(rcvdSynOpts)

	n.initGSO()

	// Register new endpoint so that packets are routed to it.
	if err := n.stack.RegisterTransportEndpoint(n.boundNICID, n.effectiveNetProtos, ProtocolNumber, n.id, n, n.reusePort); err != nil {
		n.Close()
		return nil, err
	}

	n.isRegistered = true
	n.state = stateConnected

	// Create sender and receiver.
	//
	// The receiver at least temporarily has a zero receive window scale,
	// but the caller may change it (before starting the protocol loop).
	n.snd = newSender(n, iss, irs, s.window, rcvdSynOpts.MSS, rcvdSynOpts.WS)
	n.rcv = newReceiver(n, irs, l.rcvWnd, 0)

	return n, nil
}
1080642
func makeJSONRPCHandler(funcMap map[string]*RPCFunc, cdc *amino.Codec, logger log.Logger) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		b, err := ioutil.ReadAll(r.Body)
		if err != nil {
			WriteRPCResponseHTTP(w, types.RPCInvalidRequestError(types.JSONRPCStringID(""), errors.Wrap(err, "Error reading request body")))
			return
		}
		// if its an empty request (like from a browser),
		// just display a list of functions
		if len(b) == 0 {
			writeListOfEndpoints(w, r, funcMap)
			return
		}

		var request types.RPCRequest
		err = json.Unmarshal(b, &request)
		if err != nil {
			WriteRPCResponseHTTP(w, types.RPCParseError(types.JSONRPCStringID(""), errors.Wrap(err, "Error unmarshalling request")))
			return
		}
		// A Notification is a Request object without an "id" member.
		// The Server MUST NOT reply to a Notification, including those that are within a batch request.
		if request.ID == types.JSONRPCStringID("") {
			logger.Debug("HTTPJSONRPC received a notification, skipping... (please send a non-empty ID if you want to call a method)")
			return
		}
		if len(r.URL.Path) > 1 {
			WriteRPCResponseHTTP(w, types.RPCInvalidRequestError(request.ID, errors.Errorf("Path %s is invalid", r.URL.Path)))
			return
		}

		rpcFunc := funcMap[request.Method]
		if rpcFunc == nil || rpcFunc.ws {
			WriteRPCResponseHTTP(w, types.RPCMethodNotFoundError(request.ID))
			return
		}

		ctx := &types.Context{JSONReq: &request, HTTPReq: r}
		args := []reflect.Value{reflect.ValueOf(ctx)}
		if len(request.Params) > 0 {
			fnArgs, err := jsonParamsToArgs(rpcFunc, cdc, request.Params)
			if err != nil {
				WriteRPCResponseHTTP(w, types.RPCInvalidParamsError(request.ID, errors.Wrap(err, "Error converting json params to arguments")))
				return
			}
			args = append(args, fnArgs...)
		}

		returns := rpcFunc.f.Call(args)

		logger.Info("HTTPJSONRPC", "method", request.Method, "args", args, "returns", returns)
		result, err := unreflectResult(returns)
		if err != nil {
			WriteRPCResponseHTTP(w, types.RPCInternalError(request.ID, err))
			return
		}
		WriteRPCResponseHTTP(w, types.NewRPCSuccessResponse(cdc, request.ID, result))
	}
}
1341882
func makeEndpoint(hostport, serviceName string) (ep *zipkincore.Endpoint) {
	ep = zipkincore.NewEndpoint()

	// Set the ServiceName
	ep.ServiceName = serviceName

	if strings.IndexByte(hostport, ':') < 0 {
		// "<host>" becomes "<host>:0"
		hostport = hostport + ":0"
	}

	// try to parse provided "<host>:<port>"
	host, port, err := net.SplitHostPort(hostport)
	if err != nil {
		// if unparsable, return as "undefined:0"
		return
	}

	// try to set port number
	p, _ := strconv.ParseUint(port, 10, 16)
	ep.Port = int16(p)

	// if <host> is a domain name, look it up
	addrs, err := net.LookupIP(host)
	if err != nil {
		// return as "undefined:<port>"
		return
	}

	var addr4, addr16 net.IP
	for i := range addrs {
		addr := addrs[i].To4()
		if addr == nil {
			// IPv6
			if addr16 == nil {
				addr16 = addrs[i].To16() // IPv6 - 16 bytes
			}
		} else {
			// IPv4
			if addr4 == nil {
				addr4 = addr // IPv4 - 4 bytes
			}
		}
		if addr16 != nil && addr4 != nil {
			// IPv4 & IPv6 have been set, we can stop looking further
			break
		}
	}
	// default to 0 filled 4 byte array for IPv4 if IPv6 only host was found
	if addr4 == nil {
		addr4 = make([]byte, 4)
	}

	// set IPv4 and IPv6 addresses
	ep.Ipv4 = (int32)(binary.BigEndian.Uint32(addr4))
	ep.Ipv6 = []byte(addr16)
	return
}
895145
func MakeClient(frontend base.ClientFacade, backend base.FacadeCaller, client *httprequest.Client) *Client {
	return &Client{
		ClientFacade: frontend,
		facade:       backend,
		client:       client,
	}
}
117028
func (r *Consumer) nextLookupdEndpoint() string {
	r.mtx.RLock()
	if r.lookupdQueryIndex >= len(r.lookupdHTTPAddrs) {
		r.lookupdQueryIndex = 0
	}
	addr := r.lookupdHTTPAddrs[r.lookupdQueryIndex]
	num := len(r.lookupdHTTPAddrs)
	r.mtx.RUnlock()
	r.lookupdQueryIndex = (r.lookupdQueryIndex + 1) % num

	urlString := addr
	if !strings.Contains(urlString, "://") {
		urlString = "http://" + addr
	}

	u, err := url.Parse(urlString)
	if err != nil {
		panic(err)
	}
	if u.Path == "/" || u.Path == "" {
		u.Path = "/lookup"
	}

	v, err := url.ParseQuery(u.RawQuery)
	v.Add("topic", r.topic)
	u.RawQuery = v.Encode()
	return u.String()
}
1270857
func NewEndpointDiscoveryWrapper(ctx context.Client, channelID string, target fab.DiscoveryService, opts ...Opt) (*DiscoveryWrapper, error) {
	chpeers := ctx.EndpointConfig().ChannelPeers(channelID)
	if len(chpeers) == 0 {
		return nil, errors.Errorf("no channel peers for channel [%s]", channelID)
	}

	s := &DiscoveryWrapper{
		DiscoveryService: target,
		chPeers:          chpeers,
		ctx:              ctx,
	}

	for _, opt := range opts {
		opt(s)
	}

	if s.filter != nil {
		s.DiscoveryService = discovery.NewDiscoveryFilterService(target, s.filter)
	}

	return s, nil
}