当前位置: 首页>>代码示例>>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;未经允许,请勿转载。