Ejemplo n.º 1
0
func main() {
	socket, err := thrift.NewTSocket("localhost:9090")
	if err != nil {
		panic(err)
	}

	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transport := transportFactory.GetTransport(socket)
	client := contact.NewContactSvcClientFactory(transport, protocolFactory)
	defer client.Transport.Close()
	if err := client.Transport.Open(); err != nil {
		panic(err)
	}

	c1 := contact.NewContactInit("Bob", "111-1111", "*****@*****.**")
	c1, err = client.Create(c1)
	if err != nil {
		panic(err)
	}

	c2, err := client.Read(c1.Id)
	if err != nil {
		panic(err)
	}
	fmt.Println(c2)
}
Ejemplo n.º 2
0
func init() {
	// init server
	server = phonebook.NewPhonebookServer(TEST_HOST)

	// init client
	socket, err := thrift.NewTSocket(TEST_HOST)
	if err != nil {
		panic(err)
	}

	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transport := transportFactory.GetTransport(socket)
	client = contact.NewContactSvcClientFactory(transport, protocolFactory)

	// run server
	go server.Run()

	// run client
	time.Sleep(2 * time.Second) // wait for server
	if err := client.Transport.Open(); err != nil {
		panic(err)
	}
}