コード例 #1
0
// 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
}
コード例 #2
0
ファイル: user.go プロジェクト: mvpmvh/DE2
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)}
}