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) }
func main() { transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() serverTransport, err := thrift.NewTServerSocket(NetworkAddr) if err != nil { log.Printf("NewTServerSocket error: %v\n", err) return } processor := translate.NewProxyTransProcessor(&proxyTrans{}) server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory) log.Println(server.Serve()) }
func NewPhonebookServer(host string) *PhonebookServer { handler := NewContactHandler() processor := contact.NewContactSvcProcessor(handler) transport, err := thrift.NewTServerSocket(host) if err != nil { panic(err) } transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory) return &PhonebookServer{ host: host, handler: handler, processor: processor, transport: transport, transportFactory: transportFactory, protocolFactory: protocolFactory, server: server, } }
func NewEchoServer(host string) *EchoServer { handler := NewEchoHandler() processor := NewEchoSrvProcessor(handler) transport, err := thrift.NewTServerSocket(host) if err != nil { panic(err) } transportFactory := thrift.NewTTransportFactory() protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory) return &EchoServer{ host: host, handler: handler, processor: processor, transport: transport, transportFactory: transportFactory, protocolFactory: protocolFactory, server: server, } }
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) } }