Exemplo n.º 1
0
func main() {
	// optionally setup command line usage
	cmd.Init()

	host, err := os.Hostname()
	if err != nil {
		log.Fatalf("Unable to obtain hostname: %s", err)
	}

	// Initialise Server
	server.Init(
		server.Name("io.jbrodriguez.mediagui.agent."+host),
		server.Address("0.0.0.0:0"),
	)

	// Register Handlers
	server.Handle(
		server.NewHandler(
			&Agent{host: host},
		),
	)

	log.Info("Agent started ")

	// Run server
	if err := server.Run(); err != nil {
		log.Info(err)
	}

}
Exemplo n.º 2
0
func main() {
	cmd.Init()

	for i := 0; i < 10; i++ {
		call(i)
	}

	stream()
	pub()
}
Exemplo n.º 3
0
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)
}
Exemplo n.º 4
0
func main() {
	// optionally setup command line usage
	cmd.Init()

	// Initialise Server
	server.Init(
		server.Name("go.micro.api.geo"),
	)

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

	// Run server
	if err := server.Run(); err != nil {
		log.Fatal(err)
	}
}
Exemplo n.º 5
0
func main() {
	cmd.Init()

	folders := []string{
		`/mnt/user/films`,
	}

	// Create new request to service go.micro.srv.example, method Example.Call
	req := client.NewRequest("io.jbrodriguez.mediagui.scanner", "Scanner.Scan", &scan.Request{
		// Folders: s.settings.MediaFolders,
		Folders: folders,
	})

	log.Infof("req=%+v", req)

	rsp := &scan.Response{}

	t0 := time.Now()

	// Call service
	if err := client.Call(context.Background(), req, rsp); err != nil {
		log.Warning("Unable to connect to scanning service: %s", err)
		return
	}

	𝛥t := float64(time.Since(t0)) / 1e9

	for _, file := range rsp.Filenames {
		log.Infof("file=%s", file)
	}

	log.Infof("walked %d files in %.3f seconds\n", len(rsp.Filenames), 𝛥t)

	ch := make(chan os.Signal, 1)
	signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
	log.Infof("Received signal %s", <-ch)
}
Exemplo n.º 6
0
func main() {
	// optionally setup command line usage
	cmd.Init()

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

	// Register Handlers
	server.Handle(
		server.NewHandler(
			new(handler.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,
		),
	)

	// Run server
	if err := server.Run(); err != nil {
		log.Fatal(err)
	}
}
Exemplo n.º 7
0
func main() {
	cmd.Init()

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

	// Set arbitrary headers in context
	ctx := c.WithMetadata(context.Background(), map[string]string{
		"X-User-Id": "john",
		"X-From-Id": "script",
	})

	rsp := &hello.Response{}

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

	fmt.Println(rsp.Msg)
}