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


Golang cmd.Init函數代碼示例

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


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

示例1: main

func main() {
	cmd.Init()

	r := router.NewRouter()
	c := client.NewClient(client.Selector(r))
	c = router.NewLabelWrapper(c)

	// Create new request to service go.micro.srv.greeter, method Say.Hello
	req := c.NewRequest("go.micro.srv.greeter", "Say.Hello", &hello.Request{
		Name: "John",
	})

	rsp := &hello.Response{}

	// Set arbitrary headers in context
	ctx := metadata.NewContext(context.Background(), map[string]string{
		router.LabelPrefix + "Greeter": "one",
	})

	// Call service
	if err := c.Call(ctx, req, rsp); err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(rsp.Msg)
}
開發者ID:micro,項目名稱:go-platform,代碼行數:27,代碼來源:labels.go

示例2: main

func main() {
	cmd.Init()
	log = logrus.New()

	service = micro.NewService(
		micro.Flags(cli.StringFlag{
			Name:   "pair",
			Value:  "USD",
			Usage:  "Select pair to subscribe",
			EnvVar: "PAIR",
		}),
		micro.Flags(cli.StringFlag{
			Name:   "currency",
			Value:  "JPY",
			Usage:  "Select pair to subscribe",
			EnvVar: "CURRENCY",
		}),
		micro.Action(func(c *cli.Context) {
			settings.pair = c.String("pair")
			settings.currency = c.String("currency")
		}),
		micro.Name("PairSubscriber"),
	)
	service.Init(getOptions)
	go exec(settings.pair, settings.currency)
	select {}
}
開發者ID:tamseo,項目名稱:nii-finance,代碼行數:27,代碼來源:service.go

示例3: main

func main() {
	cmd.Init()
	fmt.Println("\n--- Publisher example ---\n")
	for i := 0; i < 10; i++ {
		pub(i)
	}
}
開發者ID:ZhuJingfa,項目名稱:go-micro,代碼行數:7,代碼來源:pub.go

示例4: main

func main() {
	cmd.Init()

	t := trace.NewTrace()

	srv := &registry.Service{
		Name: "go.client",
	}

	client.DefaultClient = client.NewClient(
		client.Wrap(
			trace.ClientWrapper(t, srv),
		),
	)

	fmt.Println("Starting trace")
	if err := t.Start(); err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("\n--- Traced Call example ---\n")
	i := 0
	for {
		call(i)
		i++
		<-time.After(time.Second * 5)
	}

	if err := t.Stop(); err != nil {
		fmt.Println(err)
	}
}
開發者ID:jelmersnoeck,項目名稱:go-platform,代碼行數:33,代碼來源:main.go

示例5: main

func main() {
	// optionally setup command line usage
	cmd.Init()

	// Initialise Server
	server.Init(
		server.Name("go.micro.srv.example"),
	)

	// Register Subscribers
	server.Subscribe(
		server.NewSubscriber(
			"topic.go.micro.srv.example",
			new(subscriber.Example),
		),
	)

	server.Subscribe(
		server.NewSubscriber(
			"topic.go.micro.srv.example",
			subscriber.Handler,
		),
	)

	// Register Handler
	example.RegisterExampleHandler(
		server.DefaultServer, new(Example),
	)

	// Run server
	if err := server.Run(); err != nil {
		log.Fatal(err)
	}
}
開發者ID:yonglehou,項目名稱:go-micro,代碼行數:34,代碼來源:codegen.go

示例6: main

func main() {
	cmd.Init()

	t := zipkin.NewTrace(
		trace.Collectors("192.168.99.100:9092"),
	)
	defer t.Close()

	client.DefaultClient = client.NewClient(
		client.Wrap(
			trace.ClientWrapper(t, nil),
		),
	)

	fmt.Println("\n--- Traced Call example ---\n")
	for i := 0; i < 10; i++ {
		call(i)
	}

	/*
		fmt.Println("\n--- Streamer example ---\n")
		stream(10)

		fmt.Println("\n--- Ping Pong example ---\n")
		pingPong(10)

		fmt.Println("\n--- Publisher example ---\n")
		pub()
	*/
	<-time.After(time.Second * 10)
}
開發者ID:ZhuJingfa,項目名稱:go-platform,代碼行數:31,代碼來源:main.go

示例7: main

func main() {
	cmd.Init()

	r := router.NewRouter()
	defer r.Close()

	ch := make(chan map[string]int, routines)
	stats := make(map[string]int)

	for i := 0; i < routines; i++ {
		go func(j int) {
			st := selector(j, r)
			str := ""
			for k, v := range st {
				str += fmt.Sprintf("stats %d %s %d\n", j, k, v)
			}
			fmt.Println(str)
			ch <- st
		}(i)
	}

	// collate stats
	for i := 0; i < routines; i++ {
		st := <-ch
		for k, v := range st {
			stats[k] += v
		}
	}

	for k, v := range stats {
		fmt.Println("overall stats", k, v)
	}
}
開發者ID:micro,項目名稱:go-platform,代碼行數:33,代碼來源:router.go

示例8: main

func main() {
	cmd.Init()

	database := db.NewDB(
		db.Database("foo"),
		db.Table("bar"),
	)

	type Thing struct {
		Name string
	}

	record := db.NewRecord(uuid.NewUUID().String(), db.Metadata{"key": "value"}, &Thing{"dbthing"})

	fmt.Printf("Creating record: id: %s metadata: %+v bytes: %+v\n", record.Id(), record.Metadata(), string(record.Bytes()))
	if err := database.Create(record); err != nil {
		fmt.Println(err)
		return
	}

	rec, err := database.Read(record.Id())
	if err != nil {
		fmt.Println(err)
		return
	}

	thing := new(Thing)

	if err := rec.Scan(&thing); err != nil {
		fmt.Println("Error scanning read record", err)
		return
	}

	fmt.Printf("Read record: id: %s metadata: %+v bytes: %+v\n", rec.Id(), rec.Metadata(), thing)

	fmt.Println("Searching for metadata key:value")
	records, err := database.Search(db.Metadata{"key": "value"}, 10, 0)
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, record := range records {
		thing := new(Thing)

		if err := record.Scan(&thing); err != nil {
			fmt.Println("Error scanning record", record.Id(), err)
			return
		}

		fmt.Printf("Record: id: %s metadata: %+v bytes: %+v\n", record.Id(), record.Metadata(), thing)
	}

	fmt.Println("Deleting", record.Id())
	if err := database.Delete(record.Id()); err != nil {
		fmt.Println(err)
		return
	}
}
開發者ID:ZhuJingfa,項目名稱:go-platform,代碼行數:59,代碼來源:db.go

示例9: main

func main() {
	cmd.Init()

	// create event handler
	ev := event.NewEvent()

	// subscribe to events
	go sub(ev)

	// publish events
	pub(ev)
}
開發者ID:micro,項目名稱:go-platform,代碼行數:12,代碼來源:event.go

示例10: main

func main() {
	cmd.Init()

	client.DefaultClient = client.NewClient(
		client.Selector(DCSelector()),
	)

	fmt.Println("\n--- Call example ---\n")
	for i := 0; i < 10; i++ {
		call(i)
	}
}
開發者ID:ZhuJingfa,項目名稱:go-micro,代碼行數:12,代碼來源:dc_selector.go

示例11: main

func main() {
	cmd.Init()

	client.DefaultClient = client.NewClient(
		client.Wrap(NewDCWrapper),
	)

	fmt.Println("\n--- Call example ---\n")
	for i := 0; i < 10; i++ {
		call(i)
	}
}
開發者ID:yonglehou,項目名稱:go-micro,代碼行數:12,代碼來源:dc_filter.go

示例12: main

func main() {
	cmd.Init()

	if err := broker.Init(); err != nil {
		log.Fatalf("Broker Init error: %v", err)
	}

	if err := broker.Connect(); err != nil {
		log.Fatalf("Broker Connect error: %v", err)
	}

	pub()
}
開發者ID:yonglehou,項目名稱:go-micro,代碼行數:13,代碼來源:producer.go

示例13: main

func main() {
	cmd.Init()

	fmt.Println("\n--- Call example ---\n")
	for i := 0; i < 10; i++ {
		call(i)
	}

	fmt.Println("\n--- Streamer example ---\n")
	stream(10)

	fmt.Println("\n--- Ping Pong example ---\n")
	pingPong(10)
}
開發者ID:ZhuJingfa,項目名稱:go-micro,代碼行數:14,代碼來源:codegen.go

示例14: main

func main() {
	// optionally setup command line usage
	cmd.Init()

	md := server.DefaultOptions().Metadata
	md["datacenter"] = "local"

	server.DefaultServer = server.NewServer(
		server.WrapHandler(logWrapper),
		server.WrapSubscriber(logSubWrapper),
		server.Metadata(md),
	)

	// Initialise Server
	server.Init(
		server.Name("go.micro.srv.example"),
	)

	// Register Handlers
	server.Handle(
		server.NewHandler(
			new(handler.Example),
		),
	)

	// Register Subscribers
	if err := server.Subscribe(
		server.NewSubscriber(
			"topic.go.micro.srv.example",
			new(subscriber.Example),
		),
	); err != nil {
		log.Fatal(err)
	}

	if err := server.Subscribe(
		server.NewSubscriber(
			"topic.go.micro.srv.example",
			subscriber.Handler,
		),
	); err != nil {
		log.Fatal(err)
	}

	// Run server
	if err := server.Run(); err != nil {
		log.Fatal(err)
	}
}
開發者ID:yonglehou,項目名稱:go-micro,代碼行數:49,代碼來源:main.go

示例15: main

func main() {
	cmd.Init()

	if err := broker.Init(); err != nil {
		log.Fatalf("Broker Init error: %v", err)
	}
	if err := broker.Connect(); err != nil {
		log.Fatalf("Broker Connect error: %v", err)
	}

	go pub()
	go sub()

	<-time.After(time.Second * 10)
}
開發者ID:yonglehou,項目名稱:go-micro,代碼行數:15,代碼來源:main.go


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