Esempio n. 1
0
// ExampleProxy shows a chain of servers and clients.
func ExampleProxy() {
	log.Println("\n***** ExampleProxy *****\n")

	// Real
	var realServer = offers.MustNewServer(configure("Real Server"), offers.Offers{Configuration: configure("Server")}, ":4030") // Use s as the service.
	go func() {
		if err := realServer.Start(); err != nil {
			panic(err)
		}
	}()
	var realClient = offers.MustNewClient(configure("Real Client"), ":4030")

	// Proxy
	var proxyServer = offers.MustNewServer(configure("Proxy Server"), realClient, ":4031") // Use realClient as the service.
	go func() {
		if err := proxyServer.Start(); err != nil {
			panic(err)
		}
	}()
	var proxyClient = offers.MustNewClient(configure("Proxy Client"), ":4031").ForContext(offers.Context{ID: tigertonic.RandomBase62String(8)}).(offers.Client)

	// Use
	m, err := proxyClient.New(offer.Offer{Name: "nerddomo"})
	if err != nil {
		panic(err)
	}
	log.Printf("New: Got: %# v\n\n", pretty.Formatter(simplify(m)))
	m, err = proxyClient.Get(m.ID)
	if err != nil {
		panic(err)
	}
	log.Printf("Get: Got: %# v\n\n", pretty.Formatter(simplify(m)))
	m.Name = "test"
	m, err = proxyClient.Set(m)
	if err != nil {
		panic(err)
	}
	log.Printf("Set: Got: %# v\n\n", pretty.Formatter(simplify(m)))
	m, err = proxyClient.Delete(m)
	if err != nil {
		panic(err)
	}
	log.Printf("Delete: Got: %# v\n\n", pretty.Formatter(simplify(m)))

	// Proxy
	if err := proxyClient.Close(); err != nil {
		panic(err)
	}
	if err := proxyServer.Stop(); err != nil {
		panic(err)
	}

	// Real
	if err := realClient.Close(); err != nil {
		panic(err)
	}
	if err := realServer.Stop(); err != nil {
		panic(err)
	}
}
Esempio n. 2
0
func TestRemote(t *testing.T) {
	// Service
	var service = offers.Offers{Configuration: offers.Configuration{OfferRepository: offer.NewRepository(mockgossie.NewMockConnectionPool())}}

	// Server
	var server = offers.MustNewServer(offers.Configuration{}, service, ":5000")
	go func() {
		if err := server.Start(); err != nil {
			panic(err)
		}
	}()

	// Client
	var client = offers.MustNewClient(offers.Configuration{}, ":5000")

	suite.Run(t, &offers.Suite{Interface: func() offers.Interface {
		return client
	}})

	// Client
	if err := client.Close(); err != nil {
		panic(err)
	}

	// Server
	if err := server.Stop(); err != nil {
		panic(err)
	}
}
Esempio n. 3
0
// ExampleMethod shows using a method.
func ExampleMethod() {
	log.Println("\n***** ExampleMethod *****\n")

	// Server
	var server = offers.MustNewServer(configure("Server"), offers.Offers{Configuration: configure("Server")}, ":4020")
	go func() {
		if err := server.Start(); err != nil {
			panic(err)
		}
	}()

	// Client
	var client = offers.MustNewClient(configure("Client"), ":4020").ForContext(offers.Context{ID: tigertonic.RandomBase62String(8)}).(offers.Client)

	// Use
	var m = offer.Offer{Interface: client, Name: "nerddomo"}
	m, err := m.New()
	if err != nil {
		panic(err)
	}
	log.Printf("New: Got: %# v\n\n", pretty.Formatter(simplify(m)))
	m, err = client.Get(m.ID)
	if err != nil {
		panic(err)
	}
	log.Printf("Get: Got: %# v\n\n", pretty.Formatter(simplify(m)))
	m.Name = "bar"
	m, err = m.Set()
	if err != nil {
		panic(err)
	}
	log.Printf("Set: Got: %# v\n\n", pretty.Formatter(simplify(m)))
	m, err = m.Delete()
	if err != nil {
		panic(err)
	}
	log.Printf("Delete: Got: %# v\n\n", pretty.Formatter(simplify(m)))

	// Client
	if err := client.Close(); err != nil {
		panic(err)
	}

	// Server
	if err := server.Stop(); err != nil {
		panic(err)
	}
}