本文整理汇总了Golang中github.com/apache/thrift/lib/go/thrift.NewTBinaryProtocolFactoryDefault函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTBinaryProtocolFactoryDefault函数的具体用法?Golang NewTBinaryProtocolFactoryDefault怎么用?Golang NewTBinaryProtocolFactoryDefault使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTBinaryProtocolFactoryDefault函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GuessProtoFactory
func GuessProtoFactory(what string) (res thrift.TProtocolFactory) {
switch what {
case "compact":
res = thrift.NewTCompactProtocolFactory()
case "simplejson":
res = thrift.NewTSimpleJSONProtocolFactory()
case "json":
res = thrift.NewTJSONProtocolFactory()
case "binary", "":
res = thrift.NewTBinaryProtocolFactoryDefault()
default:
res = thrift.NewTBinaryProtocolFactoryDefault()
}
return
}
开发者ID:godeep,项目名称:goth,代码行数:15,代码来源:guess.go
示例2: GetTOptions
// Get clone of default Thrift client options or just return first
// given. This logic is little funny. But very convenient for per-client
// options.
func GetTOptions(options ...*TOptions) (res *TOptions) {
if len(options) > 0 {
return options[0]
}
if defaultTOptions == nil {
defaultTOptions = &TOptions{
DiscoveryBase: ".thrift",
DiscoveryEnv: "",
TransportFactory: thrift.NewTFramedTransportFactory(
thrift.NewTTransportFactory()),
DialTimeout: time.Minute * 3,
PoolCapacity: 32,
PoolMax: 256,
PoolTTL: time.Hour,
ProtoFactory: func() thrift.TProtocolFactory {
return thrift.NewTBinaryProtocolFactoryDefault()
},
Ctx: context.Background(),
HubFactory: DefaultTTransportHub,
}
}
clone := *defaultTOptions
res = &clone
return
}
开发者ID:godeep,项目名称:goth,代码行数:28,代码来源:options.go
示例3: Start
func (s *ThriftServer) Start() (err error) {
processor := wire.NewBarProcessor(s.Handler)
var transport t_thrift.TServerTransport
if transport, err = t_thrift.NewTServerSocket(s.options.Bind); err != nil {
return
}
protoFactory := t_thrift.NewTBinaryProtocolFactoryDefault()
transportFactory := t_thrift.NewTBufferedTransportFactory(
s.BufferSize)
s.TServer = t_thrift.NewTSimpleServer4(processor, transport,
transportFactory, protoFactory)
logx.Debugf("thrift listening at %s", s.options.Info.RPCEndpoints[0])
errChan := make(chan error, 1)
go func() {
errChan <- s.TServer.Serve()
}()
defer s.TServer.Stop()
defer s.cancel()
select {
case <-s.ctx.Done():
return
case err = <-errChan:
return
}
return
}
开发者ID:pombredanne,项目名称:bar,代码行数:31,代码来源:thrift.go
示例4: Start
// Start starts an Apache Thrift server on port 8088
func Start() {
// We expose the following endpoints:
// /thrift/ThriftTest:
// Thrift service using TBinaryProtocol
// /thrift/SecondService
// Thrift service using TBinaryProtocol
// /thrift/mutliplexed
// Thrift service using TBinaryProtocol with TMultiplexedProtocol,
// serving both, ThriftTest and SecondService
pfactory := thrift.NewTBinaryProtocolFactoryDefault()
thriftTest := gauntlet_apache.NewThriftTestProcessor(thriftTestHandler{})
secondService := gauntlet_apache.NewSecondServiceProcessor(secondServiceHandler{})
multiplexed := thrift.NewTMultiplexedProcessor()
multiplexed.RegisterProcessor("ThriftTest", thriftTest)
multiplexed.RegisterProcessor("SecondService", secondService)
mux := http.NewServeMux()
mux.HandleFunc("/thrift/ThriftTest", thrift.NewThriftHandlerFunc(thriftTest, pfactory, pfactory))
mux.HandleFunc("/thrift/SecondService", thrift.NewThriftHandlerFunc(secondService, pfactory, pfactory))
mux.HandleFunc("/thrift/multiplexed", thrift.NewThriftHandlerFunc(multiplexed, pfactory, pfactory))
server = net.NewHTTPServer(&http.Server{
Addr: addr,
Handler: mux,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
})
if err := server.ListenAndServe(); err != nil {
log.Fatalf("failed to start Apache Thrift server: %v", err)
}
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:36,代码来源:server.go
示例5: Test_Proto_Thrift
func Test_Proto_Thrift(t *testing.T) {
t.Skip()
server := &TServer{}
err := server.Start(thrift.NewTTransportFactory())
assert.NoError(t, err)
defer server.Server.Stop()
var transport thrift.TTransport
transport, err = thrift.NewTSocket(fmt.Sprintf("127.0.0.1:%d", server.Port))
assert.NoError(t, err)
transportFactory := thrift.NewTTransportFactory()
transport = transportFactory.GetTransport(transport)
err = transport.Open()
assert.NoError(t, err)
defer transport.Close()
protoFactory := thrift.NewTBinaryProtocolFactoryDefault()
client := srv.NewTSrvClientFactory(transport, protoFactory)
req := srv.TestRep{
ID: "test",
Data: []byte("mama myla ramy"),
}
res, err := client.Test(&req)
assert.NoError(t, err)
assert.EqualValues(t, req, *res)
}
开发者ID:pombredanne,项目名称:bar,代码行数:29,代码来源:t10_test.go
示例6: New
// New returns a stateful factory for Sum and Concat Endpoints
func New(protocol string, bufferSize int, framed bool, logger log.Logger) client {
var protocolFactory thrift.TProtocolFactory
switch protocol {
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary", "":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
default:
panic("invalid protocol")
}
var transportFactory thrift.TTransportFactory
if bufferSize > 0 {
transportFactory = thrift.NewTBufferedTransportFactory(bufferSize)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if framed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
return client{transportFactory, protocolFactory, logger}
}
开发者ID:qband,项目名称:down,代码行数:28,代码来源:client.go
示例7: NewThriftServer
// New thrift server with defaults and common
func NewThriftServer(processor thrift.TProcessor) (res *TServer) {
res = &TServer{
ProtoFactory: thrift.NewTBinaryProtocolFactoryDefault(),
TransportFactory: thrift.NewTTransportFactory(),
Processor: processor,
}
return
}
开发者ID:godeep,项目名称:goth,代码行数:9,代码来源:thrift.go
示例8: NewTPool
func NewTPool(endpoints []string, bufferSize int, n int, ttl time.Duration) (res *TPool) {
res = &TPool{
endpoints: endpoints,
endpointsCap: len(endpoints) - 1,
ttl: ttl,
transportFactory: thrift.NewTBufferedTransportFactory(bufferSize),
protoFactory: thrift.NewTBinaryProtocolFactoryDefault(),
}
res.ResourcePool = pools.NewResourcePool(res.factory, n, n, ttl)
return
}
开发者ID:pombredanne,项目名称:bar,代码行数:11,代码来源:tpool.go
示例9: main
func main() {
transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
transport, err := thrift.NewTSocket(net.JoinHostPort("218.244.131.175", "8900"))
if err != nil {
fmt.Fprintln(os.Stderr, "error resolving address:", err)
os.Exit(1)
}
useTransport := transportFactory.GetTransport(transport)
client := ui2bs.NewBSServiceClientFactory(useTransport, protocolFactory)
if err := transport.Open(); err != nil {
fmt.Fprintln(os.Stderr, "Error opening socket to 127.0.0.1:8084", " ", err)
os.Exit(1)
}
defer transport.Close()
bs_req := new(ui2bs.BSRequest)
bs_req.Searchid = "123"
bs_req.Media = new(ui2bs.Media)
bs_req.Media.Appsid = "123"
bs_req.Media.ChannelId = "123"
bs_req.Adslot = new(ui2bs.AdSlot)
bs_req.Device = new(ui2bs.Device)
bs_req.Device.Os = ui2bs.OSType_ANDROID
bs_resp := new(ui2bs.BSResponse)
// bs_resp.Ads = new([]ui2bs.Ad)
bs_resp, err = client.Search(bs_req)
if err != nil {
fmt.Println("error occuse")
fmt.Println(err)
}
// for i:=0; i < 10; i++ {
// err := client.Search2()
// if err != nil {
// fmt.Println("serach fail")
// transport, err = thrift.NewTSocket(net.JoinHostPort("127.0.0.1", "8084"))
// transport.Open()
// useTransport = transportFactory.GetTransport(transport)
// client = bs.NewBSServiceClientFactory(useTransport, protocolFactory)
// }
// time.Sleep(1*time.Second)
// }
//
fmt.Println(bs_resp)
fmt.Println("I am exit ")
}
开发者ID:ifzz,项目名称:seller_adptor,代码行数:50,代码来源:client_stub.go
示例10: main
func main() {
transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
serverTransport, err := thrift.NewTServerSocket(NetworkAddr)
if err != nil {
fmt.Println("new socket fail")
}
handler := &BsServiceImpl{}
processor := bs.NewBSServiceProcessor(handler)
server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
fmt.Println("server start")
server.Serve()
}
开发者ID:ifzz,项目名称:seller_adptor,代码行数:17,代码来源:bs_stub.go
示例11: Start
func (s *TServer) Start(transportFactory thrift.TTransportFactory) (err error) {
if s.Port, err = fixtures.GetOpenPort(); err != nil {
return
}
protoFactory := thrift.NewTBinaryProtocolFactoryDefault()
processor := srv.NewTSrvProcessor(&service{})
var transport thrift.TServerTransport
if transport, err = thrift.NewTServerSocket(fmt.Sprintf(":%d", s.Port)); err != nil {
return
}
s.Server = thrift.NewTSimpleServer4(processor, transport,
transportFactory, protoFactory)
go s.Server.Serve()
time.Sleep(time.Millisecond * 100)
return
}
开发者ID:pombredanne,项目名称:bar,代码行数:18,代码来源:t10_test.go
示例12: newScribeServer
func newScribeServer(t *testing.T) *scribeServer {
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
var port int
var transport *thrift.TServerSocket
var err error
for i := 0; i < 10; i++ {
port = 10000 + rand.Intn(10000)
transport, err = thrift.NewTServerSocket(fmt.Sprintf(":%d", port))
if err != nil {
t.Logf("port %d: %v", port, err)
continue
}
break
}
if err != nil {
t.Fatal(err)
}
handler := newScribeHandler(t)
server := thrift.NewTSimpleServer4(
scribe.NewScribeProcessor(handler),
transport,
transportFactory,
protocolFactory,
)
go server.Serve()
deadline := time.Now().Add(time.Second)
for !canConnect(port) {
if time.Now().After(deadline) {
t.Fatal("server never started")
}
time.Sleep(time.Millisecond)
}
return &scribeServer{
transport: transport,
address: fmt.Sprintf("127.0.0.1:%d", port),
handler: handler,
}
}
开发者ID:jllopis,项目名称:kit,代码行数:44,代码来源:collector_test.go
示例13: main
func main() {
transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
transport, err := thrift.NewTSocket(net.JoinHostPort("127.0.0.1", "19090"))
if err != nil {
fmt.Fprintln(os.Stderr, "error resolving address:", err)
os.Exit(1)
}
useTransport := transportFactory.GetTransport(transport)
client := account.NewAccountClientFactory(useTransport, protocolFactory)
if err := transport.Open(); err != nil {
fmt.Fprintln(os.Stderr, "Error opening socket to 127.0.0.1:19090", "", err)
os.Exit(1)
}
defer transport.Close()
// 第一个请求,登录账号
request := &account.Request{
Name: "super",
Password: "123",
Op: account.Operation_LOGIN,
}
r, err := client.DoAction(request)
fmt.Println(r)
// 第二个请求,注册账号
request.Op = account.Operation_REGISTER
r, err = client.DoAction(request)
fmt.Println(r)
// 第三个请求,name为空的请求
request.Name = ""
r, err = client.DoAction(request)
fmt.Println(r)
}
开发者ID:LC2010,项目名称:thrift-step-by-step-go,代码行数:39,代码来源:account_client.go
示例14: Benchmark_Proto_Thrift_Buffered
func Benchmark_Proto_Thrift_Buffered(b *testing.B) {
b.Skip()
server := &TServer{}
err := server.Start(thrift.NewTBufferedTransportFactory(thrift_buffer))
assert.NoError(b, err)
defer server.Server.Stop()
var transport thrift.TTransport
transport, err = thrift.NewTSocket(fmt.Sprintf("127.0.0.1:%d", server.Port))
assert.NoError(b, err)
transportFactory := thrift.NewTBufferedTransportFactory(thrift_buffer)
transport = transportFactory.GetTransport(transport)
err = transport.Open()
assert.NoError(b, err)
defer transport.Close()
protoFactory := thrift.NewTBinaryProtocolFactoryDefault()
client := srv.NewTSrvClientFactory(transport, protoFactory)
b.Log(server.Port, b.N)
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StartTimer()
req := srv.TestRep{
ID: fmt.Sprintf("%d", i),
Data: []byte("mama myla ramy"),
}
res, err := client.Test(&req)
b.StopTimer()
assert.NoError(b, err)
assert.EqualValues(b, req, *res)
b.SetBytes(int64(len(req.Data) * 2))
}
}
开发者ID:pombredanne,项目名称:bar,代码行数:37,代码来源:t10_test.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 := zipkinquery.NewZipkinQueryClientFactory(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 "getTraceIds":
if flag.NArg()-1 != 1 {
fmt.Fprintln(os.Stderr, "GetTraceIds requires 1 args")
flag.Usage()
}
arg77 := flag.Arg(1)
mbTrans78 := thrift.NewTMemoryBufferLen(len(arg77))
defer mbTrans78.Close()
_, err79 := mbTrans78.WriteString(arg77)
if err79 != nil {
//.........这里部分代码省略.........
开发者ID:cnicolov,项目名称:kit,代码行数:101,代码来源:zipkin_query-remote.go
示例16: main
//.........这里部分代码省略.........
traceConcat = zipkin.ToContext(newConcatSpan, tracingLogger)
mux = http.NewServeMux()
sum, concat endpoint.Endpoint
)
sum = makeSumEndpoint(svc)
sum = zipkin.AnnotateServer(newSumSpan, collector)(sum)
mux.Handle("/sum", httptransport.NewServer(
root,
sum,
server.DecodeSumRequest,
server.EncodeSumResponse,
httptransport.ServerBefore(traceSum),
httptransport.ServerErrorLogger(transportLogger),
))
concat = makeConcatEndpoint(svc)
concat = zipkin.AnnotateServer(newConcatSpan, collector)(concat)
mux.Handle("/concat", httptransport.NewServer(
root,
concat,
server.DecodeConcatRequest,
server.EncodeConcatResponse,
httptransport.ServerBefore(traceConcat),
httptransport.ServerErrorLogger(transportLogger),
))
transportLogger.Log("addr", *httpAddr)
errc <- http.ListenAndServe(*httpAddr, mux)
}()
// Transport: gRPC
go func() {
transportLogger := log.NewContext(logger).With("transport", "gRPC")
ln, err := net.Listen("tcp", *grpcAddr)
if err != nil {
errc <- err
return
}
s := grpc.NewServer() // uses its own, internal context
pb.RegisterAddServer(s, grpcBinding{svc})
transportLogger.Log("addr", *grpcAddr)
errc <- s.Serve(ln)
}()
// Transport: net/rpc
go func() {
transportLogger := log.NewContext(logger).With("transport", "net/rpc")
s := rpc.NewServer()
if err := s.RegisterName("addsvc", netrpcBinding{svc}); err != nil {
errc <- err
return
}
s.HandleHTTP(rpc.DefaultRPCPath, rpc.DefaultDebugPath)
transportLogger.Log("addr", *netrpcAddr)
errc <- http.ListenAndServe(*netrpcAddr, s)
}()
// Transport: Thrift
go func() {
var protocolFactory thrift.TProtocolFactory
switch *thriftProtocol {
case "binary":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
default:
errc <- fmt.Errorf("invalid Thrift protocol %q", *thriftProtocol)
return
}
var transportFactory thrift.TTransportFactory
if *thriftBufferSize > 0 {
transportFactory = thrift.NewTBufferedTransportFactory(*thriftBufferSize)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if *thriftFramed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
transport, err := thrift.NewTServerSocket(*thriftAddr)
if err != nil {
errc <- err
return
}
transportLogger := log.NewContext(logger).With("transport", "net/rpc")
transportLogger.Log("addr", *thriftAddr)
errc <- thrift.NewTSimpleServer4(
thriftadd.NewAddServiceProcessor(thriftBinding{svc}),
transport,
transportFactory,
protocolFactory,
).Serve()
}()
logger.Log("fatal", <-errc)
}
开发者ID:simonjefford,项目名称:kit,代码行数:101,代码来源:main.go
示例17: main
func main() {
var (
transport = flag.String("transport", "httpjson", "httpjson, grpc, netrpc, thrift")
httpAddr = flag.String("http.addr", "localhost:8001", "Address for HTTP (JSON) server")
grpcAddr = flag.String("grpc.addr", "localhost:8002", "Address for gRPC server")
netrpcAddr = flag.String("netrpc.addr", "localhost:8003", "Address for net/rpc server")
thriftAddr = flag.String("thrift.addr", "localhost:8004", "Address for Thrift server")
thriftProtocol = flag.String("thrift.protocol", "binary", "binary, compact, json, simplejson")
thriftBufferSize = flag.Int("thrift.buffer.size", 0, "0 for unbuffered")
thriftFramed = flag.Bool("thrift.framed", false, "true to enable framing")
)
flag.Parse()
if len(os.Args) < 4 {
fmt.Fprintf(os.Stderr, "\n%s [flags] method arg1 arg2\n\n", filepath.Base(os.Args[0]))
flag.Usage()
os.Exit(1)
}
root := context.Background()
method, s1, s2 := flag.Arg(0), flag.Arg(1), flag.Arg(2)
var logger log.Logger
logger = log.NewLogfmtLogger(os.Stdout)
logger = log.NewContext(logger).With("caller", log.DefaultCaller)
logger = log.NewContext(logger).With("transport", *transport)
var svc server.AddService
switch *transport {
case "grpc":
cc, err := grpc.Dial(*grpcAddr)
if err != nil {
_ = logger.Log("err", err)
os.Exit(1)
}
defer cc.Close()
svc = grpcclient.New(root, cc, logger)
case "httpjson":
rawurl := *httpAddr
if !strings.HasPrefix("http", rawurl) {
rawurl = "http://" + rawurl
}
baseurl, err := url.Parse(rawurl)
if err != nil {
_ = logger.Log("err", err)
os.Exit(1)
}
svc = httpjsonclient.New(root, baseurl, logger, nil)
case "netrpc":
cli, err := rpc.DialHTTP("tcp", *netrpcAddr)
if err != nil {
_ = logger.Log("err", err)
os.Exit(1)
}
defer cli.Close()
svc = netrpcclient.New(cli, logger)
case "thrift":
var protocolFactory thrift.TProtocolFactory
switch *thriftProtocol {
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary", "":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
default:
_ = logger.Log("protocol", *thriftProtocol, "err", "invalid protocol")
os.Exit(1)
}
var transportFactory thrift.TTransportFactory
if *thriftBufferSize > 0 {
transportFactory = thrift.NewTBufferedTransportFactory(*thriftBufferSize)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if *thriftFramed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
transportSocket, err := thrift.NewTSocket(*thriftAddr)
if err != nil {
_ = logger.Log("during", "thrift.NewTSocket", "err", err)
os.Exit(1)
}
trans := transportFactory.GetTransport(transportSocket)
defer trans.Close()
if err := trans.Open(); err != nil {
_ = logger.Log("during", "thrift transport.Open", "err", err)
os.Exit(1)
}
cli := thriftadd.NewAddServiceClientFactory(trans, protocolFactory)
svc = thriftclient.New(cli, logger)
default:
_ = logger.Log("err", "invalid transport")
os.Exit(1)
}
//.........这里部分代码省略.........
开发者ID:nimmen,项目名称:kit,代码行数:101,代码来源:main.go
示例18: 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 := scribe.NewScribeClientFactory(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 "Log":
if flag.NArg()-1 != 1 {
fmt.Fprintln(os.Stderr, "Log requires 1 args")
flag.Usage()
}
arg5 := flag.Arg(1)
mbTrans6 := thrift.NewTMemoryBufferLen(len(arg5))
defer mbTrans6.Close()
_, err7 := mbTrans6.WriteString(arg5)
if err7 != nil {
//.........这里部分代码省略.........
开发者ID:cnicolov,项目名称:kit,代码行数:101,代码来源:scribe-remote.go
示例19: 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 := zipkincollector.NewZipkinCollectorClientFactory(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 "storeTopAnnotations":
if flag.NArg()-1 != 2 {
fmt.Fprintln(os.Stderr, "StoreTopAnnotations requires 2 args")
flag.Usage()
}
argvalue0 := flag.Arg(1)
value0 := argvalue0
arg10 := flag.Arg(2)
mbTrans11 := thrift.NewTMemoryBufferLen(len(arg10))
defer mbTrans11.Close()
//.........这里部分代码省略.........
开发者ID:cnicolov,项目名称:kit,代码行数:101,代码来源:zipkin_collector-remote.go
示例20: newConnection
func newConnection(node, keyspace string, timeout int, authentication map[string]string) (*connection, error) {
addr, err := net.ResolveTCPAddr("tcp", node)
if err != nil {
return nil, err
}
c := &connection{node: node}
c.socket = thrift.NewTSocketFromAddrTimeout(addr, 0)
// socket not open yet, so no error expected.
c.socket.SetTimeout(time.Duration(timeout) * time.Millisecond)
c.transport = thrift.NewTFramedTransport(c.socket)
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
c.client = cassandra.NewCassandraClientFactory(c.transport, protocolFactory)
// simulate timeout support for the underlying Dial() in .Open(). needless to say this sucks
// restore sanity to this for Go v1 with the new DialTimeout() func
ch := make(chan bool, 1)
go func() {
err = c.transport.Open()
ch <- true
}()
timedOut := false
select {
case <-time.After(time.Duration(timeout) * time.Millisecond):
timedOut = true
case <-ch:
}
if timedOut {
return nil, ErrorConnectionTimeout
}
if err != nil {
return nil, err
}
version, err := c.client.DescribeVersion()
if err != nil {
c.close()
return nil, err
}
versionComponents := strings.Split(version, ".")
if len(versionComponents) < 1 {
return nil, ErrorInvalidThriftVersion
}
majorVersion, err := strconv.Atoi(versionComponents[0])
if err != nil {
return nil, ErrorInvalidThriftVersion
}
if majorVersion < LOWEST_COMPATIBLE_VERSION {
return nil, ErrorWrongThriftVersion
}
if len(authentication) > 0 {
ar := cassandra.NewAuthenticationRequest()
ar.Credentials = make(map[string]string)
for k, v := range authentication {
ar.Credentials[k] = v
}
err := c.client.Login(ar)
if err != nil {
switch err.(type) {
case *cassandra.AuthenticationException:
return nil, ErrorAuthenticationFailed
case *cassandra.AuthorizationException:
return nil, ErrorAuthorizationFailed
default:
return nil, err
}
}
}
err = c.client.SetKeyspace(keyspace)
if err != nil {
switch err.(type) {
case *cassandra.InvalidRequestException:
c.close()
return nil, ErrorSetKeyspace
default:
c.close()
return nil, err
}
}
c.keyspace = keyspace
return c, nil
}
开发者ID:hailocab,项目名称:gossie,代码行数:88,代码来源:connection.go
注:本文中的github.com/apache/thrift/lib/go/thrift.NewTBinaryProtocolFactoryDefault函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论