當前位置: 首頁>>代碼示例>>Golang>>正文


Golang thrift.TTransport類代碼示例

本文整理匯總了Golang中git/apache/org/thrift/git/lib/go/thrift.TTransport的典型用法代碼示例。如果您正苦於以下問題:Golang TTransport類的具體用法?Golang TTransport怎麽用?Golang TTransport使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TTransport類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	var err error
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	var transport thrift.TTransport
	transport, err = thrift.NewTSocket(listen)
	if err != nil {
		fmt.Println("error, thrift init!")
		return
	}
	transport = transportFactory.GetTransport(transport)
	defer transport.Close()
	if err := transport.Open(); err != nil {
		fmt.Printf("error %v\n", err)
		return
	}
	client := puller.NewPullerClientFactory(transport, protocolFactory)
	var request puller.Request
	request.UserId = 12398
	request.Payload = "dlrow olleh"
	var response *puller.Response
	response, err = client.Pull(&request)
	if err != nil {
		fmt.Printf("error, response[%v]\n", err)
		return
	}
	fmt.Printf("response:[%v]\n", response)
}
開發者ID:visilicon,項目名稱:thrift-go,代碼行數:28,代碼來源:main.go

示例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))
}
開發者ID:glycerine,項目名稱:golang-thrift-minimal-example,代碼行數:30,代碼來源:client.go

示例3: Open

// opens a hive connection
func (conn *HiveConnection) Open() error {

	log.Println("creating new hive connection ")
	var transport thrift.TTransport
	var err error
	transport, err = thrift.NewTSocket(conn.Server)
	if err != nil {
		return err
	}
	if transport == nil {
		return errors.New("No TSocket connection?")
	}

	transport.Open()

	// NewTBinaryProtocolTransport(t TTransport) *TBinaryProtocol {
	protocolfac := thrift.NewTBinaryProtocolFactoryDefault()

	//NewThriftHiveClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol)
	conn.Client = thrifthive.NewThriftHiveClientFactory(transport, protocolfac)

	log.Printf("is open? %v", transport.IsOpen())
	name, err := conn.Client.GetName()
	log.Printf("in conn.Open, how is client? %v %v", name, err)

	if conn.Client == nil {
		log.Println("ERROR, no client")
		return errors.New("no client")
	}

	return nil
}
開發者ID:lasithasenanayake,項目名稱:v6engine-deps,代碼行數:33,代碼來源:hiveclient.go

示例4: 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))
}
開發者ID:Rheeseyb,項目名稱:thrift,代碼行數:14,代碼來源:client.go

示例5: 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))
}
開發者ID:y-okubo,項目名稱:thrift-test,代碼行數:18,代碼來源:main.go

示例6: CreateConnection

//創建一個thrift的client
func CreateConnection() (interface{}, error) {
	var client *hello.HelloClient
	var transport thrift.TTransport
	transportFactory := thrift.NewTTransportFactory()
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	raw_transport, e1 := thrift.NewTSocket(net.JoinHostPort(CTR_HOST, CTR_HOST_PORT))
	if e1 != nil {
		return client, e1
	}
	transport = transportFactory.GetTransport(raw_transport)
	e2 := transport.Open()
	if e2 != nil {
		return client, e2
	}

	client = hello.NewHelloClientFactory(transport, protocolFactory)
	return client, nil
}
開發者ID:houcy,項目名稱:thrift-connection-pool,代碼行數:19,代碼來源:demo_client.go

示例7: 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))
}
開發者ID:zhaorui1,項目名稱:thrift-rpc-framework,代碼行數:21,代碼來源:driver_test.go

示例8: runClient

func runClient(addr string) *ops.ProducerClient {
	var transport thrift.TTransport
	var err error
	socket, err := thrift.NewTSocket(addr)
	if err != nil {
		fmt.Println("Error opening socket:", err)
		return nil
	}
	transportFactory := thrift.NewTTransportFactory()
	if transportFactory == nil {
		fmt.Println("Failed to create new TransportFactory")
		return nil
	}
	transport = transportFactory.GetTransport(socket)
	if err := transport.Open(); err != nil {
		fmt.Println("Failed to connect to", addr)
		return nil
	}
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	return ops.NewProducerClientFactory(transport, protocolFactory)
}
開發者ID:jamwyatt,項目名稱:Thrift-golang,代碼行數:21,代碼來源:client.go

示例9: ThriftClientFactory

// ThriftClientFactory is an thrift Client factory which creates a connection
// that uses a thrift codec.
func ThriftClientFactory(addr string) func() (io.Closer, error) {
	return func() (io.Closer, error) {
		var transport thrift.TTransport
		socketTransport, err := thrift.NewTSocketTimeout(addr, defaultTimeout)
		if err != nil {
			return nil, err
		}
		transport = thrift.NewTFramedTransport(
			thrift.NewTBufferedTransport(socketTransport, defaultBufferSize))
		protocol := thrift.NewTBinaryProtocolFactoryDefault()
		if err := transport.Open(); err != nil {
			return nil, err
		}

		client := NewHbaseClientFactory(transport, protocol)
		return &clientCloser{
			mu:          &sync.Mutex{},
			conn:        socketTransport,
			HbaseClient: client,
		}, nil
	}
}
開發者ID:csigo,項目名稱:hbase,代碼行數:24,代碼來源:client.go

示例10: Open

func (c *ThriftConnection) Open() error {
	if c.connection != nil {
		Logger.Printf("WARNING re-opening thrigt client connection")
	}
	var transport thrift.TTransport
	var err error
	socket, err := thrift.NewTSocket(fmt.Sprintf("%s:%d", c.addr, c.port))
	if err != nil {
		Logger.Printf("Error opening socket: %s", err)
		return err
	}
	transportFactory := thrift.NewTTransportFactory()
	transport = transportFactory.GetTransport(socket)
	if err := transport.Open(); err != nil {
		Logger.Printf("Thrift client failed to connect to: %s:%d: %s", c.addr, c.port, err)
		return err
	}
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	c.connection = messages.NewDataStoreClientFactory(transport, protocolFactory)
	Logger.Printf("Thrift connection: %s:%d connected", c.addr, c.port)
	return nil
}
開發者ID:jamwyatt,項目名稱:ServicesWebThriftEtcd,代碼行數:22,代碼來源:thriftClient.go

示例11: NewUserService

func NewUserService() *services.UserService {
	var transport thrift.TTransport
	var err error

	addr := beego.AppConfig.String("socketAddress")

	if transport, err = thrift.NewTSocket(addr); err != nil {
		panic("Unable to initialize socket!")
	}

	transportFactory := thrift.NewTTransportFactory()
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	transport = transportFactory.GetTransport(transport)

	if !transport.IsOpen() {
		if err = transport.Open(); err != nil {
			panic("Unable to open socket!")
		}
	}

	return &services.UserService{user.NewUserServicerClientFactory(transport, protocolFactory)}
}
開發者ID:mvpmvh,項目名稱:DE2,代碼行數:23,代碼來源:user.go

示例12: 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)
}
開發者ID:kevinhuo88888,項目名稱:o3erp,代碼行數:36,代碼來源:thriftservice.go

示例13: main

func main() {
	flag.Usage = Usage
	var host string
	var port int
	var protocol string
	var urlString string
	var framed bool
	var useHttp bool
	var parsedUrl url.URL
	var trans thrift.TTransport
	_ = strconv.Atoi
	_ = math.Abs
	flag.Usage = Usage
	flag.StringVar(&host, "h", "localhost", "Specify host and port")
	flag.IntVar(&port, "p", 9090, "Specify port")
	flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)")
	flag.StringVar(&urlString, "u", "", "Specify the url")
	flag.BoolVar(&framed, "framed", false, "Use framed transport")
	flag.BoolVar(&useHttp, "http", false, "Use http")
	flag.Parse()

	if len(urlString) > 0 {
		parsedUrl, err := url.Parse(urlString)
		if err != nil {
			fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
			flag.Usage()
		}
		host = parsedUrl.Host
		useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http"
	} else if useHttp {
		_, err := url.Parse(fmt.Sprint("http://", host, ":", port))
		if err != nil {
			fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
			flag.Usage()
		}
	}

	cmd := flag.Arg(0)
	var err error
	if useHttp {
		trans, err = thrift.NewTHttpClient(parsedUrl.String())
	} else {
		portStr := fmt.Sprint(port)
		if strings.Contains(host, ":") {
			host, portStr, err = net.SplitHostPort(host)
			if err != nil {
				fmt.Fprintln(os.Stderr, "error with host:", err)
				os.Exit(1)
			}
		}
		trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr))
		if err != nil {
			fmt.Fprintln(os.Stderr, "error resolving address:", err)
			os.Exit(1)
		}
		if framed {
			trans = thrift.NewTFramedTransport(trans)
		}
	}
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error creating transport", err)
		os.Exit(1)
	}
	defer trans.Close()
	var protocolFactory thrift.TProtocolFactory
	switch protocol {
	case "compact":
		protocolFactory = thrift.NewTCompactProtocolFactory()
		break
	case "simplejson":
		protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
		break
	case "json":
		protocolFactory = thrift.NewTJSONProtocolFactory()
		break
	case "binary", "":
		protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
		break
	default:
		fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol)
		Usage()
		os.Exit(1)
	}
	client := tcliservice.NewTCLIServiceClientFactory(trans, protocolFactory)
	if err := trans.Open(); err != nil {
		fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
		os.Exit(1)
	}

	switch cmd {
	case "OpenSession":
		if flag.NArg()-1 != 1 {
			fmt.Fprintln(os.Stderr, "OpenSession requires 1 args")
			flag.Usage()
		}
		arg60 := flag.Arg(1)
		mbTrans61 := thrift.NewTMemoryBufferLen(len(arg60))
		defer mbTrans61.Close()
		_, err62 := mbTrans61.WriteString(arg60)
		if err62 != nil {
//.........這裏部分代碼省略.........
開發者ID:charithe,項目名稱:hivething,代碼行數:101,代碼來源:t_c_l_i_service-remote.go

示例14: main

func main() {
	flag.Usage = Usage
	var host string
	var port int
	var protocol string
	var urlString string
	var framed bool
	var useHttp bool
	var parsedUrl url.URL
	var trans thrift.TTransport
	_ = strconv.Atoi
	_ = math.Abs
	flag.Usage = Usage
	flag.StringVar(&host, "h", "localhost", "Specify host and port")
	flag.IntVar(&port, "p", 9090, "Specify port")
	flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)")
	flag.StringVar(&urlString, "u", "", "Specify the url")
	flag.BoolVar(&framed, "framed", false, "Use framed transport")
	flag.BoolVar(&useHttp, "http", false, "Use http")
	flag.Parse()

	if len(urlString) > 0 {
		parsedUrl, err := url.Parse(urlString)
		if err != nil {
			fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
			flag.Usage()
		}
		host = parsedUrl.Host
		useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http"
	} else if useHttp {
		_, err := url.Parse(fmt.Sprint("http://", host, ":", port))
		if err != nil {
			fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
			flag.Usage()
		}
	}

	cmd := flag.Arg(0)
	var err error
	if useHttp {
		trans, err = thrift.NewTHttpClient(parsedUrl.String())
	} else {
		portStr := fmt.Sprint(port)
		if strings.Contains(host, ":") {
			host, portStr, err = net.SplitHostPort(host)
			if err != nil {
				fmt.Fprintln(os.Stderr, "error with host:", err)
				os.Exit(1)
			}
		}
		trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr))
		if err != nil {
			fmt.Fprintln(os.Stderr, "error resolving address:", err)
			os.Exit(1)
		}
		if framed {
			trans = thrift.NewTFramedTransport(trans)
		}
	}
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error creating transport", err)
		os.Exit(1)
	}
	defer trans.Close()
	var protocolFactory thrift.TProtocolFactory
	switch protocol {
	case "compact":
		protocolFactory = thrift.NewTCompactProtocolFactory()
		break
	case "simplejson":
		protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
		break
	case "json":
		protocolFactory = thrift.NewTJSONProtocolFactory()
		break
	case "binary", "":
		protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
		break
	default:
		fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol)
		Usage()
		os.Exit(1)
	}
	client := services.NewAreaSvcClientFactory(trans, protocolFactory)
	if err := trans.Open(); err != nil {
		fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
		os.Exit(1)
	}

	switch cmd {
	case "createArea":
		if flag.NArg()-1 != 2 {
			fmt.Fprintln(os.Stderr, "CreateArea requires 2 args")
			flag.Usage()
		}
		argvalue0 := flag.Arg(1)
		value0 := argvalue0
		arg144 := flag.Arg(2)
		mbTrans145 := thrift.NewTMemoryBufferLen(len(arg144))
		defer mbTrans145.Close()
//.........這裏部分代碼省略.........
開發者ID:sebsofen,項目名稱:sportapp-server,代碼行數:101,代碼來源:area_svc-remote.go

示例15: main

func main() {
	flag.Usage = Usage
	var host string
	var port int
	var protocol string
	var urlString string
	var framed bool
	var useHttp bool
	var parsedUrl url.URL
	var trans thrift.TTransport
	_ = strconv.Atoi
	_ = math.Abs
	flag.Usage = Usage
	flag.StringVar(&host, "h", "localhost", "Specify host and port")
	flag.IntVar(&port, "p", 9090, "Specify port")
	flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)")
	flag.StringVar(&urlString, "u", "", "Specify the url")
	flag.BoolVar(&framed, "framed", false, "Use framed transport")
	flag.BoolVar(&useHttp, "http", false, "Use http")
	flag.Parse()

	if len(urlString) > 0 {
		parsedUrl, err := url.Parse(urlString)
		if err != nil {
			fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
			flag.Usage()
		}
		host = parsedUrl.Host
		useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http"
	} else if useHttp {
		_, err := url.Parse(fmt.Sprint("http://", host, ":", port))
		if err != nil {
			fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
			flag.Usage()
		}
	}

	cmd := flag.Arg(0)
	var err error
	if useHttp {
		trans, err = thrift.NewTHttpClient(parsedUrl.String())
	} else {
		portStr := fmt.Sprint(port)
		if strings.Contains(host, ":") {
			host, portStr, err = net.SplitHostPort(host)
			if err != nil {
				fmt.Fprintln(os.Stderr, "error with host:", err)
				os.Exit(1)
			}
		}
		trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr))
		if err != nil {
			fmt.Fprintln(os.Stderr, "error resolving address:", err)
			os.Exit(1)
		}
		if framed {
			trans = thrift.NewTFramedTransport(trans)
		}
	}
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error creating transport", err)
		os.Exit(1)
	}
	defer trans.Close()
	var protocolFactory thrift.TProtocolFactory
	switch protocol {
	case "compact":
		protocolFactory = thrift.NewTCompactProtocolFactory()
		break
	case "simplejson":
		protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
		break
	case "json":
		protocolFactory = thrift.NewTJSONProtocolFactory()
		break
	case "binary", "":
		protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
		break
	default:
		fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol)
		Usage()
		os.Exit(1)
	}
	client := service.NewSystemServiceClientFactory(trans, protocolFactory)
	if err := trans.Open(); err != nil {
		fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
		os.Exit(1)
	}

	switch cmd {
	case "ActiveFontUser":
		if flag.NArg()-1 != 2 {
			fmt.Fprintln(os.Stderr, "ActiveFontUser requires 2 args")
			flag.Usage()
		}
		tmp0, err28 := (strconv.Atoi(flag.Arg(1)))
		if err28 != nil {
			Usage()
			return
		}
//.........這裏部分代碼省略.........
開發者ID:huodon,項目名稱:tyful,代碼行數:101,代碼來源:system_service-remote.go


注:本文中的git/apache/org/thrift/git/lib/go/thrift.TTransport類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。