本文整理汇总了Golang中git/apache/org/thrift/git/lib/go/thrift.TTransportFactory.GetTransport方法的典型用法代码示例。如果您正苦于以下问题:Golang TTransportFactory.GetTransport方法的具体用法?Golang TTransportFactory.GetTransport怎么用?Golang TTransportFactory.GetTransport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git/apache/org/thrift/git/lib/go/thrift.TTransportFactory
的用法示例。
在下文中一共展示了TTransportFactory.GetTransport方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runClient
func runClient(transportFactory thrift.TTransportFactory,
protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
opts := nats.DefaultOptions
opts.Servers = []string{addr}
opts.Secure = secure
conn, err := opts.Connect()
if err != nil {
return err
}
defer conn.Close()
transport, err := thrift_nats.NATSTransportFactory(conn, "foo", time.Second, time.Second)
if err != nil {
return err
}
transport = transportFactory.GetTransport(transport)
defer transport.Close()
if err := transport.Open(); err != nil {
return err
}
return handleClient(tutorial.NewCalculatorClientFactory(transport, protocolFactory))
}
示例2: runClient
func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
var transport thrift.TTransport
var err error
if secure {
cfg := new(tls.Config)
cfg.InsecureSkipVerify = true
transport, err = thrift.NewTSSLSocket(addr, cfg)
} else {
transport, err = thrift.NewTSocket(addr)
}
if err != nil {
fmt.Println("Error opening socket:", err)
return err
}
if transport == nil {
return fmt.Errorf("Error opening socket, got nil transport. Is server available?")
}
transport = transportFactory.GetTransport(transport)
if transport == nil {
return fmt.Errorf("Error from transportFactory.GetTransport(), got nil transport. Is server available?")
}
err = transport.Open()
if err != nil {
return err
}
defer transport.Close()
return handleClient(tutorial.NewCalculatorClientFactory(transport, protocolFactory))
}
示例3: runClient
func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string) error {
var transport thrift.TTransport
transport, err := thrift.NewTSocket(addr)
if err != nil {
fmt.Println("Error opening socket:", err)
return err
}
transport = transportFactory.GetTransport(transport)
defer transport.Close()
if err := transport.Open(); err != nil {
return err
}
return handleClient(tutorial.NewCalculatorClientFactory(transport, protocolFactory))
}
示例4: runClient
func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
var transport thrift.TTransport
var err error
transport, err = thrift.NewTSocket(addr)
if err != nil {
fmt.Println("Error opening socket:", err)
return err
}
transport = transportFactory.GetTransport(transport)
defer transport.Close()
if err := transport.Open(); err != nil {
return err
}
return handleClient(awesome_service.NewAwesomeServiceClientFactory(transport, protocolFactory))
}
示例5: NewThriftRequestExec
func NewThriftRequestExec(tFac thrift.TTransportFactory, clientExec ThriftClientExecutor, timeout time.Duration, hosts ...string) bender.RequestExecutor {
return func(_ int64, request interface{}) (interface{}, error) {
addr := hosts[rand.Intn(len(hosts))]
socket, err := thrift.NewTSocketTimeout(addr, timeout)
if err != nil {
return nil, err
}
defer socket.Close()
transport := tFac.GetTransport(socket)
if err := transport.Open(); err != nil {
return nil, err
}
defer transport.Close()
return clientExec(request, transport)
}
}
示例6: Update
func Update(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, variable *person.Person) (*person.Person, error) {
socket, err := thrift.NewTSocket("localhost:4000")
if err != nil {
log.Println(err)
}
transport := transportFactory.GetTransport(socket)
client := person.NewPersonServiceClientFactory(transport, protocolFactory)
defer client.Transport.Close()
if err := client.Transport.Open(); err != nil {
log.Println(err)
}
result, err := client.Update(variable)
if err != nil {
log.Println(err)
return nil, err
}
return result, nil
}
示例7: Delete
func Delete(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, id int64) error {
socket, err := thrift.NewTSocket("localhost:4000")
if err != nil {
log.Println(err)
}
transport := transportFactory.GetTransport(socket)
client := person.NewPersonServiceClientFactory(transport, protocolFactory)
defer client.Transport.Close()
if err := client.Transport.Open(); err != nil {
log.Println(err)
}
err = client.Destroy(id)
if err != nil {
log.Println(err)
return err
}
return nil
}
示例8: RunClient
func RunClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
var transport thrift.TTransport
var err error
if secure {
cfg := new(tls.Config)
cfg.InsecureSkipVerify = true
transport, err = thrift.NewTSSLSocket(addr, cfg)
} else {
transport, err = thrift.NewTSocket(addr)
}
if err != nil {
fmt.Println("Error opening socket:", err)
return err
}
transport = transportFactory.GetTransport(transport)
defer transport.Close()
if err := transport.Open(); err != nil {
return err
}
return HandleClient(addrservice.NewAddressServiceClientFactory(transport, protocolFactory))
}
示例9: RunThriftService
func RunThriftService(thriftFunc ThriftFunc) (map[string]string, error) {
//addr := flag.String("addr", "localhost:9090", "Address to listen to")
//secure := flag.Bool("secure", false, "Use tls secure transport")
//flag.Parse()
addr := "localhost:9090"
secure := true
var protocolFactory thrift.TProtocolFactory
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
var transportFactory thrift.TTransportFactory
transportFactory = thrift.NewTTransportFactory()
var transport thrift.TTransport
var err error
if secure {
cfg := new(tls.Config)
cfg.InsecureSkipVerify = true
transport, err = thrift.NewTSSLSocket(addr, cfg)
} else {
transport, err = thrift.NewTSocket(addr)
}
if err != nil {
fmt.Println("Error opening socket:", err)
return nil, err
}
transport = transportFactory.GetTransport(transport)
defer transport.Close()
if err := transport.Open(); err != nil {
return nil, err
}
client := thriftlib.NewBaseServiceClientFactory(transport, protocolFactory)
return thriftFunc(client)
}
示例10: testHappyPath
func testHappyPath(t *testing.T, proto thrift.TProtocolFactory, buffered, framed bool) {
options := nats.DefaultOptions
options.Servers = []string{fmt.Sprintf("nats://localhost:%d", port)}
serverConn, err := options.Connect()
if err != nil {
t.Fatal("Failed to connect to gnatsd", err)
}
defer serverConn.Close()
clientConn, err := options.Connect()
if err != nil {
t.Fatal("Failed to connect to gnatsd", err)
}
defer clientConn.Close()
var transportFactory thrift.TTransportFactory
if buffered {
transportFactory = thrift.NewTBufferedTransportFactory(8192)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if framed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
processor := tutorial.NewCalculatorProcessor(NewCalculatorHandler())
server := thrift_nats.NewNATSServer(serverConn, subject, -1, -1, processor,
transportFactory, proto)
wait := make(chan bool)
go func() {
wait <- true
if err := server.Serve(); err != nil {
t.Fatal("Failed to start thrift server", err)
}
}()
<-wait
defer server.Stop()
// Give the server a chance to start.
time.Sleep(500 * time.Millisecond)
transport, err := thrift_nats.NATSTransportFactory(clientConn, subject, time.Second, -1)
if err != nil {
t.Fatal("Failed to create NATS transport", err)
}
transport = transportFactory.GetTransport(transport)
if err := transport.Open(); err != nil {
t.Fatal("Failed to open transport", err)
}
defer transport.Close()
client := tutorial.NewCalculatorClientFactory(transport, proto)
if err := client.Ping(); err != nil {
t.Fatal("Ping failed", err)
}
if err := client.Zip(); err != nil {
t.Fatal("Zip failed", err)
}
sum, err := client.Add(1, 1)
if err != nil {
t.Fatal("Sum failed", err)
}
if sum != 2 {
t.Fatalf("Expected Sum result 2, got %d", sum)
}
work := tutorial.NewWork()
work.Op = tutorial.Operation_DIVIDE
work.Num1 = 8
work.Num2 = 4
quotient, err := client.Calculate(1, work)
if err != nil {
t.Fatal("Calculate failed", err)
}
if sum != 2 {
t.Fatalf("Expected Calculate result 4, got %d", quotient)
}
work.Op = tutorial.Operation_DIVIDE
work.Num1 = 1
work.Num2 = 0
_, err = client.Calculate(2, work)
switch v := err.(type) {
case *tutorial.InvalidOperation:
break
default:
t.Fatalf("Expected Calculate to return InvalidOperation, got %s", v)
}
log, err := client.GetStruct(1)
if err != nil {
t.Fatal("GetStruct failed", err)
}
if log.Value != "2" {
t.Fatalf("Expected struct value `2`, got `%s`", log.Value)
}
log, err = client.GetStruct(2)
if err != nil {
//.........这里部分代码省略.........
示例11: RunThrifter
func RunThrifter(index int, dataChan chan *demoThrift.RequestInfo) {
var err error = nil
var data *demoThrift.RequestInfo
for {
if err != nil { // wait for a while when retry
time.Sleep(time.Duration(30) * time.Second)
}
secure := false
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
//transportFactory := thrift.NewTTransportFactory()
var transportFactory thrift.TTransportFactory
//transportFactory = thrift.NewTBufferedTransportFactory(8192)
transportFactory = thrift.NewTTransportFactory()
//transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
var transport thrift.TTransport
if secure {
cfg := new(tls.Config)
cfg.InsecureSkipVerify = true
transport, err = thrift.NewTSSLSocket(ThrifterAddr, cfg)
} else {
transport, err = thrift.NewTSocket(ThrifterAddr)
}
if err != nil {
Log.Error("[No.%d sender] Error opening socket: %s", index, err)
continue
}
transport = transportFactory.GetTransport(transport)
if err = transport.Open(); err != nil {
Log.Error("[No.%d sender] Error opening transport: %s", index, err)
continue
}
client := demoThrift.NewDemoThriftClientFactory(transport, protocolFactory)
if client == nil {
Log.Error("[No.%d sender] Error new unify-client", index)
transport.Close()
continue
}
Log.Info("[No.%d sender] connected to judge center", index)
// loop for sending
for {
if data == nil {
data = <-dataChan
}
//Log.Info("No.%d sender work!", index)
var result string
// retry times
for i := 0; i < 2; i++ {
result, err = client.SendtoParser(data)
if err != nil {
Log.Error("[No.%d sender] client.SendtoParser failed, result: %s, err: %s", index, result, err.Error())
time.Sleep(time.Duration(5) * time.Second)
continue
}
data = nil
Log.Info("[No.%d sender] get result: %s", index, result)
break
}
if err != nil {
// reconnect
transport.Close()
Log.Info("[No.%d sender] try to reconnect, err: %s", index, err.Error())
break
}
}
}
}