当前位置: 首页>>代码示例>>Golang>>正文


Golang application.Context类代码示例

本文整理汇总了Golang中mojo/public/go/application.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Context类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Initialize

func (d *delegate) Initialize(ctx application.Context) {
	req, ptr := discovery.CreateMessagePipeForDiscovery()
	ctx.ConnectToApplication("https://mojo.v.io/discovery.mojo").ConnectToService(&req)

	ad := discovery.Advertisement{
		InterfaceName: "v.io/discovery.T",
		Addresses:     []string{"localhost:1000"},
		Attributes:    &map[string]string{"foo": "abc"},
		Attachments:   &map[string][]byte{"bar": []byte{1, 2, 3}},
	}
	dProxy := discovery.NewDiscoveryProxy(ptr, bindings.GetAsyncWaiter())
	id, closerPtr, e1, e2 := dProxy.Advertise(ad, nil)
	if e1 != nil || e2 != nil {
		log.Printf("Failed to advertise: %v, %v", e1, e2)
		return
	}
	log.Printf("Advertising %x...", *id)

	d.stop = func() {
		cProxy := discovery.NewCloserProxy(*closerPtr, bindings.GetAsyncWaiter())
		cProxy.Close()
		cProxy.Close_Proxy()

		dProxy.Close_Proxy()
	}
}
开发者ID:vanadium,项目名称:mojo.discovery,代码行数:26,代码来源:advertiser.go

示例2: Initialize

func (d *HttpHandlerDelegate) Initialize(ctx application.Context) {
	request, pointer := http_server_factory.CreateMessagePipeForHttpServerFactory()
	ctx.ConnectToApplication("mojo:http_server").ConnectToService(&request)
	factory := http_server_factory.NewHttpServerFactoryProxy(pointer, bindings.GetAsyncWaiter())

	addr := &net_address.NetAddress{
		net_address.NetAddressFamily_IpV4,
		&net_address.NetAddressIPv4{
			8080,
			[4]uint8{127, 0, 0, 1},
		},
		nil,
	}
	serverRequest, serverPointer := http_server.CreateMessagePipeForHttpServer()
	factory.CreateHttpServer(serverRequest, addr)
	d.server = http_server.NewHttpServerProxy(serverPointer, bindings.GetAsyncWaiter())
	handlerRequest, handlerPointer := http_server.CreateMessagePipeForHttpHandler()
	ok, err := d.server.SetHandler("/go", handlerPointer)
	if !ok {
		log.Println("can't set handler:", err)
		return
	}

	d.handlerStub = http_server.NewHttpHandlerStub(handlerRequest, &HttpHandler{}, bindings.GetAsyncWaiter())
	go func() {
		for {
			if err := d.handlerStub.ServeRequest(); err != nil {
				log.Println("can't handle http request:", err)
				return
			}
		}
	}()
	factory.Close_Proxy()
}
开发者ID:Miaque,项目名称:mojo,代码行数:34,代码来源:http_handler.go

示例3: Initialize

func (delegate *TestClientDelegate) Initialize(ctx application.Context) {
	log.Printf("TestClientDelegate.Initialize...")

	// Set the necessary flags using the mojo args.
	args := ctx.Args()
	mojoFlag = flag.NewFlagSet(args[0], flag.ExitOnError)
	mojoRun := mojoFlag.String("test.run", "", "")
	mojoBench := mojoFlag.String("test.bench", "", "")
	endpointFlag = mojoFlag.String("endpoint", "", "")
	v23TcpAddr := mojoFlag.String("v23.tcp.address", "", "")
	mojoFlag.Parse(args[1:])
	flag.Set("test.run", *mojoRun)
	flag.Set("test.bench", *mojoBench)
	flag.Set("v23.tcp.address", *v23TcpAddr)

	tests := []func(*testing.T, application.Context){
		TestSimple, TestMultiArgs, TestReuseProxy, TestNoOutArgs,
	}
	benchmarks := []func(*testing.B, application.Context){
		BenchmarkSimpleRpc,
	}

	matchAllTests := func(pat, str string) (bool, error) { return true, nil }
	exitCode := testing.MainStart(matchAllTests, convertTests(tests, ctx), convertBenchmarks(benchmarks, ctx), nil).Run()
	if exitCode == 0 {
		fmt.Printf("%s\n", expected.SuccessMessage)
	} else {
		fmt.Printf("%s\n", expected.FailureMessage)
	}

	ctx.Close()
	os.Exit(exitCode)
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:33,代码来源:test_client.go

示例4: newGlobalDiscovery

func newGlobalDiscovery(mctx application.Context, scanInterval time.Duration) *mojom.Discovery_Proxy {
	u, _ := url.Parse("https://mojo.v.io/discovery.mojo")
	q := u.Query()
	q.Set(QueryGlobal, "a/b/c")
	q.Set(QueryScanInterval, fmt.Sprintf("%.3fs", scanInterval.Seconds()))
	u.RawQuery = q.Encode()

	req, ptr := mojom.CreateMessagePipeForDiscovery()
	mctx.ConnectToApplication(u.String()).ConnectToService(&req)
	return mojom.NewDiscoveryProxy(ptr, bindings.GetAsyncWaiter())
}
开发者ID:vanadium,项目名称:mojo.discovery,代码行数:11,代码来源:global_discovery_apptest.go

示例5: Initialize

func (delegate *EchoClientDelegate) Initialize(ctx application.Context) {
	echoRequest, echoPointer := echo.CreateMessagePipeForEcho()
	ctx.ConnectToApplication("mojo:go_echo_server").ConnectToService(&echoRequest)
	echoProxy := echo.NewEchoProxy(echoPointer, bindings.GetAsyncWaiter())
	response, err := echoProxy.EchoString(bindings.StringPointer("Hello, Go world!"))
	if response != nil {
		fmt.Printf("client: %s\n", *response)
	} else {
		log.Println(err)
	}
	echoProxy.Close_Proxy()
	ctx.Close()
}
开发者ID:Miaque,项目名称:mojo,代码行数:13,代码来源:echo_client.go

示例6: Initialize

// When running echo_client, ctx.Args() should contain:
// 0: mojo app name
// 1: remote endpoint
// 2+: string to echo
func (delegate *RemoteEchoClientDelegate) Initialize(ctx application.Context) {
	log.Printf("RemoteEchoClientDelegate.Initialize...")

	// Parse arguments. Note: May panic if not enough args are given.
	remoteEndpoint := ctx.Args()[1]
	echoString := "Hello, Go world!"
	if len(ctx.Args()) > 2 {
		echoString = strings.Join(ctx.Args()[2:], " ")
	}

	r, p := echo.CreateMessagePipeForRemoteEcho()

	v23.ConnectToRemoteService(ctx, &r, remoteEndpoint)
	echoProxy := echo.NewRemoteEchoProxy(p, bindings.GetAsyncWaiter())

	log.Printf("RemoteEchoClientDelegate.Initialize calling EchoString...")
	response, err := echoProxy.EchoString(echoString)
	if err == nil {
		fmt.Printf("client: %s\n", response)
	} else {
		fmt.Printf("error: %v\n", err)
	}

	log.Printf("RemoteEchoClientDelegate.Initialize calling EchoX...")
	response2, err := echoProxy.EchoX([]bool{true, false, false, true}, echo.AInArg{"A String"})
	if err == nil {
		fmt.Printf("client: %v\n", response2)
	} else {
		log.Println("Error: ", err)
	}

	fmt.Printf("(done)\n")
	echoProxy.Close_Proxy()
	ctx.Close()
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:39,代码来源:echo_client.go

示例7: ConnectToRemoteService

func ConnectToRemoteService(ctx application.Context, r application.ServiceRequest, v23Name string) {
	v23r, v23p := v23clientproxy.CreateMessagePipeForV23ClientProxy()
	ctx.ConnectToApplication("https://mojo.v.io/v23clientproxy.mojo").ConnectToService(&v23r)
	prox := v23clientproxy.NewV23ClientProxyProxy(v23p, bindings.GetAsyncWaiter())
	sd := r.ServiceDescription()
	mojomInterfaceType, err := sd.GetTopLevelInterface()
	if err != nil {
		// The service description must have the MojomInterface type.
		panic(err)
	}
	desc, err := sd.GetAllTypeDefinitions()
	if err != nil {
		// The service description must have the map of UserDefinedTypes.
		panic(err)
	}

	prox.SetupClientProxy(v23Name, mojomInterfaceType, *desc, r.Name(), r.PassMessagePipe())
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:18,代码来源:client.go

示例8: Initialize

// When running fortune_client, ctx.Args() should contain:
// 0: mojo app name
// 1: remote endpoint
// 2+: (optional) fortune to add
// If the fortune to add is omitted, then the fortune_client will Get a fortune.
// Otherwise, it will Add the given fortune.
func (delegate *FortuneClientDelegate) Initialize(ctx application.Context) {
	// Parse the arguments.
	remoteEndpoint := ctx.Args()[1]
	addFortune := strings.Join(ctx.Args()[2:], " ")

	log.Printf("FortuneClientDelegate.Initialize... %s", remoteEndpoint)
	fortuneRequest, fortunePointer := fortune.CreateMessagePipeForFortune()
	v23.ConnectToRemoteService(ctx, &fortuneRequest, remoteEndpoint)
	fortuneProxy := fortune.NewFortuneProxy(fortunePointer, bindings.GetAsyncWaiter())

	if addFortune != "" {
		log.Printf("FortuneClientDelegate.Initialize calling Add...")

		if err := fortuneProxy.Add(addFortune); err != nil {
			log.Println(err)
		} else {
			fmt.Printf("client added: %s\n", addFortune)
		}
	} else {
		log.Printf("FortuneClientDelegate.Initialize calling Get...")
		response, err := fortuneProxy.Get()
		if response != "" {
			fmt.Printf("client (get): %s\n", response)
		} else {
			log.Println(err)
		}
	}

	fortuneProxy.Close_Proxy()
	ctx.Close()
}
开发者ID:vanadium,项目名称:mojo.v23proxy,代码行数:37,代码来源:fortune_client.go

示例9: Initialize

func (d *HttpServerDelegate) Initialize(ctx application.Context) {
	request, pointer := network_service.CreateMessagePipeForNetworkService()
	ctx.ConnectToApplication("mojo:network_service").ConnectToService(&request)
	d.networkService = network_service.NewNetworkServiceProxy(pointer, bindings.GetAsyncWaiter())

	if err := d.InitTCPBoundSocket(); err != nil {
		log.Printf("can't create TCP socket: %v\n", err)
		return
	}
	if err := d.InitServerSocket(); err != nil {
		log.Printf("can't create server socket: %v\n", err)
		return
	}

	http.HandleFunc("/go", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, Go http server!")
	})
	l := &MojoListener{d.serverSocket}
	if err := http.Serve(l, nil); err != nil {
		log.Printf("can't serve request: %v\n", err)
		return
	}
}
开发者ID:willbittner,项目名称:mojo,代码行数:23,代码来源:http_server.go

示例10: Initialize

func (d *delegate) Initialize(ctx application.Context) {
	req, ptr := discovery.CreateMessagePipeForDiscovery()
	ctx.ConnectToApplication("https://mojo.v.io/discovery.mojo").ConnectToService(&req)

	scanHandlerReq, scanHandlerPtr := discovery.CreateMessagePipeForScanHandler()
	scanHandlerStub := discovery.NewScanHandlerStub(scanHandlerReq, &scanHandler{}, bindings.GetAsyncWaiter())

	dProxy := discovery.NewDiscoveryProxy(ptr, bindings.GetAsyncWaiter())
	closerPtr, e1, e2 := dProxy.Scan(`v.InterfaceName="v.io/discovery.T"`, scanHandlerPtr)
	if e1 != nil || e2 != nil {
		log.Printf("Failed to scan: %v, %v", e1, e2)
		scanHandlerStub.Close()
		dProxy.Close_Proxy()
		return
	}

	go func() {
		for {
			if err := scanHandlerStub.ServeRequest(); err != nil {
				connErr, ok := err.(*bindings.ConnectionError)
				if !ok || !connErr.Closed() {
					log.Println(err)
				}
				break
			}
		}
	}()

	d.stop = func() {
		cProxy := discovery.NewCloserProxy(*closerPtr, bindings.GetAsyncWaiter())
		cProxy.Close()
		cProxy.Close_Proxy()

		scanHandlerStub.Close()
		dProxy.Close_Proxy()
	}
}
开发者ID:vanadium,项目名称:mojo.discovery,代码行数:37,代码来源:scanner.go

示例11: Initialize

// Initialize connects to other instance, providing and asking for echo service.
func (delegate *EchoDelegate) Initialize(ctx application.Context) {
	if ctx.URL() != delegate.localURL {
		panic(fmt.Sprintf("invalid URL: want %v, got %v", delegate.localURL, ctx.URL()))
	}
	if len(ctx.Args()) != 1 || ctx.Args()[0] != delegate.localURL {
		panic(fmt.Sprintf("invalid args: want %v, got %v", []string{delegate.localURL}, ctx.Args()))
	}
	go func() {
		echoRequest, echoPointer := echo.CreateMessagePipeForEcho()
		conn := ctx.ConnectToApplication(pairedURL(delegate.localURL), &echo.Echo_ServiceFactory{delegate})
		if conn.RequestorURL() != delegate.localURL {
			panic(fmt.Sprintf("invalid requestor URL: want %v, got %v", delegate.localURL, conn.RequestorURL()))
		}
		if conn.ConnectionURL() != pairedURL(delegate.localURL) {
			panic(fmt.Sprintf("invalid connection URL: want %v, got %v", pairedURL(delegate.localURL), conn.ConnectionURL()))
		}
		conn.ConnectToService(&echoRequest)
		checkEcho(echoPointer)
	}()
}
开发者ID:willbittner,项目名称:mojo,代码行数:21,代码来源:application_impl_test.go


注:本文中的mojo/public/go/application.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。