當前位置: 首頁>>代碼示例>>Golang>>正文


Golang util.NewUnresolvedAddr函數代碼示例

本文整理匯總了Golang中github.com/cockroachdb/cockroach/util.NewUnresolvedAddr函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewUnresolvedAddr函數的具體用法?Golang NewUnresolvedAddr怎麽用?Golang NewUnresolvedAddr使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewUnresolvedAddr函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: checkOfficialize

func checkOfficialize(t *testing.T, network, oldAddrString, newAddrString, expAddrString string) {
	unresolvedAddr := util.NewUnresolvedAddr(network, oldAddrString)
	resolvedAddr := util.NewUnresolvedAddr(network, newAddrString)

	if err := officializeAddr(unresolvedAddr, resolvedAddr); err != nil {
		t.Fatal(err)
	}

	if retAddrString := unresolvedAddr.String(); retAddrString != expAddrString {
		t.Errorf("officializeAddr(%s, %s) was %s; expected %s", oldAddrString, newAddrString, retAddrString, expAddrString)
	}
}
開發者ID:JackKrupansky,項目名稱:cockroach,代碼行數:12,代碼來源:server_test.go

示例2: Start

// Start starts the server on the specified port, starts gossip and
// initializes the node using the engines from the server's context.
func (s *Server) Start() error {
	tlsConfig, err := s.ctx.GetServerTLSConfig()
	if err != nil {
		return err
	}

	unresolvedAddr := util.NewUnresolvedAddr("tcp", s.ctx.Addr)
	ln, err := util.ListenAndServe(s.stopper, s, unresolvedAddr, tlsConfig)
	if err != nil {
		return err
	}
	s.listener = ln // Only used in tests.

	if err := officializeAddr(unresolvedAddr, ln.Addr()); err != nil {
		return err
	}

	s.rpcContext.SetLocalServer(s.rpc, unresolvedAddr.String())

	s.grpc = grpc.NewServer()
	s.gossip.Start(s.grpc, unresolvedAddr)

	if err := s.node.start(s.rpc, unresolvedAddr, s.ctx.Engines, s.ctx.NodeAttributes); err != nil {
		return err
	}

	// Begin recording runtime statistics.
	runtime := status.NewRuntimeStatRecorder(s.node.Descriptor.NodeID, s.clock)
	s.tsDB.PollSource(runtime, s.ctx.MetricsFrequency, ts.Resolution10s, s.stopper)

	// Begin recording time series data collected by the status monitor.
	s.recorder = status.NewNodeStatusRecorder(s.node.status, s.clock)
	s.tsDB.PollSource(s.recorder, s.ctx.MetricsFrequency, ts.Resolution10s, s.stopper)

	// Begin recording status summaries.
	s.startWriteSummaries()

	s.sqlServer.SetNodeID(s.node.Descriptor.NodeID)
	// Create and start the schema change manager only after a NodeID
	// has been assigned.
	s.schemaChangeManager = sql.NewSchemaChangeManager(*s.db, s.gossip, s.leaseMgr)
	s.schemaChangeManager.Start(s.stopper)

	s.status = newStatusServer(s.db, s.gossip, s.registry, s.ctx)

	log.Infof("starting %s server at %s", s.ctx.HTTPRequestScheme(), unresolvedAddr)
	s.initHTTP()

	return s.pgServer.Start(util.NewUnresolvedAddr("tcp", s.ctx.PGAddr))
}
開發者ID:fndaily,項目名稱:cockroach,代碼行數:52,代碼來源:server.go

示例3: GetAddress

func (tr *testResolver) GetAddress() (net.Addr, error) {
	defer func() { tr.numTries++ }()
	if tr.numTries < tr.numFails {
		return nil, errors.New("bad address")
	}
	return util.NewUnresolvedAddr("tcp", tr.addr), nil
}
開發者ID:GitGoldie,項目名稱:cockroach,代碼行數:7,代碼來源:client_test.go

示例4: officialAddr

func officialAddr(unresolvedAddr string, resolvedAddr net.Addr) (*util.UnresolvedAddr, error) {
	unresolvedHost, unresolvedPort, err := net.SplitHostPort(unresolvedAddr)
	if err != nil {
		return nil, err
	}

	resolvedHost, resolvedPort, err := net.SplitHostPort(resolvedAddr.String())
	if err != nil {
		return nil, err
	}

	var host string
	if unresolvedHost != "" {
		// A host was provided, use it.
		host = unresolvedHost
	} else {
		// A host was not provided. Ask the system, and fall back to the listener.
		if hostname, err := os.Hostname(); err == nil {
			host = hostname
		} else {
			host = resolvedHost
		}
	}

	var port string
	if unresolvedPort != "0" {
		// A port was provided, use it.
		port = unresolvedPort
	} else {
		// A port was not provided, but the system assigned one.
		port = resolvedPort
	}

	return util.NewUnresolvedAddr(resolvedAddr.Network(), net.JoinHostPort(host, port)), nil
}
開發者ID:mrtracy,項目名稱:cockroach,代碼行數:35,代碼來源:server.go

示例5: GetAddress

func (tr *testResolver) GetAddress() (net.Addr, error) {
	// Fail 3 times...
	tr.tries++
	if tr.tries < 3 {
		return nil, errors.New("bad address")
	}
	return util.NewUnresolvedAddr("tcp", tr.addr), nil
}
開發者ID:liugangnhm,項目名稱:cockroach,代碼行數:8,代碼來源:client_test.go

示例6: resolveAddress

func resolveAddress(network, address string) (net.Addr, error) {
	if network == "tcp" {
		_, err := net.ResolveTCPAddr("tcp", address)
		if err != nil {
			return nil, err
		}
		return util.NewUnresolvedAddr("tcp", address), nil
	}
	return nil, util.Errorf("unknown address type: %q", network)
}
開發者ID:danieldeb,項目名稱:cockroach,代碼行數:10,代碼來源:node_lookup.go

示例7: TestClientCloseBeforeConnect

// TestClientCloseBeforeConnect verifies that the client goroutine
// does not leak if the client is closed before connecting.
func TestClientCloseBeforeConnect(t *testing.T) {
	defer leaktest.AfterTest(t)()

	c := NewClient(
		util.NewUnresolvedAddr("tcp", ":1337"),
		&Context{Stopper: stop.NewStopper()},
	)

	c.Close()
}
開發者ID:liugangnhm,項目名稱:cockroach,代碼行數:12,代碼來源:client_test.go

示例8: GetAddress

// GetAddress returns a net.Addr or error.
func (sr *socketResolver) GetAddress() (net.Addr, error) {
	switch sr.typ {
	case "tcp":
		_, err := net.ResolveTCPAddr("tcp", sr.addr)
		if err != nil {
			return nil, err
		}
		return util.NewUnresolvedAddr("tcp", sr.addr), nil
	}
	return nil, errors.Errorf("unknown address type: %q", sr.typ)
}
開發者ID:CubeLite,項目名稱:cockroach,代碼行數:12,代碼來源:socket.go

示例9: GetAddress

// GetAddress returns a net.Addr or error.
func (sr *socketResolver) GetAddress() (net.Addr, error) {
	switch sr.typ {
	case "unix":
		addr, err := net.ResolveUnixAddr("unix", sr.addr)
		if err != nil {
			return nil, err
		}
		sr.exhausted = true
		return addr, nil
	case "tcp":
		_, err := net.ResolveTCPAddr("tcp", sr.addr)
		if err != nil {
			return nil, err
		}
		sr.exhausted = true
		return util.NewUnresolvedAddr("tcp", sr.addr), nil
	}
	return nil, util.Errorf("unknown address type: %q", sr.typ)
}
開發者ID:cuongdo,項目名稱:cockroach,代碼行數:20,代碼來源:socket.go

示例10: GetAddress

// GetAddress returns a net.Addr or error.
func (sr *socketResolver) GetAddress() (net.Addr, error) {
	switch sr.typ {
	case "unix":
		addr, err := net.ResolveUnixAddr("unix", sr.addr)
		if err != nil {
			return nil, err
		}
		sr.exhausted = true
		return addr, nil
	case "tcp", "lb":
		_, err := net.ResolveTCPAddr("tcp", sr.addr)
		if err != nil {
			return nil, err
		}
		if sr.typ == "tcp" {
			// "tcp" resolvers point to a single host. "lb" have an unknown of number of backends.
			sr.exhausted = true
		}
		return util.NewUnresolvedAddr("tcp", sr.addr), nil
	}
	return nil, util.Errorf("unknown address type: %q", sr.typ)
}
開發者ID:danieldeb,項目名稱:cockroach,代碼行數:23,代碼來源:socket.go

示例11: makeTestGossip

	"github.com/cockroachdb/cockroach/util/leaktest"
)

var testRangeDescriptor = roachpb.RangeDescriptor{
	RangeID:  1,
	StartKey: roachpb.RKey("a"),
	EndKey:   roachpb.RKey("z"),
	Replicas: []roachpb.ReplicaDescriptor{
		{
			NodeID:  1,
			StoreID: 1,
		},
	},
}

var testAddress = util.NewUnresolvedAddr("tcp", "node1")

func makeTestGossip(t *testing.T) (*gossip.Gossip, func()) {
	n := simulation.NewNetwork(1)
	g := n.Nodes[0].Gossip

	if err := g.AddInfo(gossip.KeySentinel, nil, time.Hour); err != nil {
		t.Fatal(err)
	}
	if err := g.AddInfoProto(gossip.KeyFirstRangeDescriptor, &testRangeDescriptor, time.Hour); err != nil {
		t.Fatal(err)
	}
	nodeIDKey := gossip.MakeNodeIDKey(1)
	if err := g.AddInfoProto(nodeIDKey, &roachpb.NodeDescriptor{
		NodeID:  1,
		Address: *testAddress,
開發者ID:cuongdo,項目名稱:cockroach,代碼行數:31,代碼來源:dist_sender_test.go


注:本文中的github.com/cockroachdb/cockroach/util.NewUnresolvedAddr函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。