github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/gossip/resolver/socket.go (about)

     1  // Copyright 2015 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package resolver
    12  
    13  import (
    14  	"net"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/util"
    17  	"github.com/cockroachdb/errors"
    18  )
    19  
    20  // socketResolver represents the different types of socket-based
    21  // address resolvers.
    22  type socketResolver struct {
    23  	typ  string
    24  	addr string
    25  }
    26  
    27  // Type returns the resolver type.
    28  func (sr *socketResolver) Type() string { return sr.typ }
    29  
    30  // Addr returns the resolver address.
    31  func (sr *socketResolver) Addr() string { return sr.addr }
    32  
    33  // GetAddress returns a net.Addr or error.
    34  func (sr *socketResolver) GetAddress() (net.Addr, error) {
    35  	switch sr.typ {
    36  	case "tcp":
    37  		_, err := net.ResolveTCPAddr("tcp", sr.addr)
    38  		if err != nil {
    39  			return nil, err
    40  		}
    41  		return util.NewUnresolvedAddr("tcp", sr.addr), nil
    42  	}
    43  	return nil, errors.Errorf("unknown address type: %q", sr.typ)
    44  }