本文整理汇总了Golang中github.com/apache/thrift/lib/go/thrift.NewTJSONProtocolFactory函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTJSONProtocolFactory函数的具体用法?Golang NewTJSONProtocolFactory怎么用?Golang NewTJSONProtocolFactory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTJSONProtocolFactory函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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}
}
示例2: 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
}
示例3: 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)
}
示例4: 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)
}
//.........这里部分代码省略.........
示例5: main
//.........这里部分代码省略.........
e = zipkin.AnnotateServer(zipkinSpanFunc, zipkinCollector)(e)
// Mechanical stuff
rand.Seed(time.Now().UnixNano())
root := context.Background()
errc := make(chan error)
go func() {
errc <- interrupt()
}()
// Transport: HTTP (debug/instrumentation)
go func() {
logger.Log("addr", *debugAddr, "transport", "debug")
errc <- http.ListenAndServe(*debugAddr, nil)
}()
// Transport: HTTP (JSON)
go func() {
ctx, cancel := context.WithCancel(root)
defer cancel()
before := []httptransport.BeforeFunc{zipkin.ToContext(zipkinSpanFunc)}
after := []httptransport.AfterFunc{}
handler := makeHTTPBinding(ctx, e, before, after)
logger.Log("addr", *httpAddr, "transport", "HTTP/JSON")
errc <- http.ListenAndServe(*httpAddr, handler)
}()
// Transport: gRPC
go func() {
ln, err := net.Listen("tcp", *grpcAddr)
if err != nil {
errc <- err
return
}
s := grpc.NewServer() // uses its own context?
pb.RegisterAddServer(s, grpcBinding{e})
logger.Log("addr", *grpcAddr, "transport", "gRPC")
errc <- s.Serve(ln)
}()
// Transport: net/rpc
go func() {
ctx, cancel := context.WithCancel(root)
defer cancel()
s := rpc.NewServer()
s.RegisterName("addsvc", NetrpcBinding{ctx, e})
s.HandleHTTP(rpc.DefaultRPCPath, rpc.DefaultDebugPath)
logger.Log("addr", *netrpcAddr, "transport", "net/rpc")
errc <- http.ListenAndServe(*netrpcAddr, s)
}()
// Transport: Thrift
go func() {
ctx, cancel := context.WithCancel(root)
defer cancel()
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
}
logger.Log("addr", *thriftAddr, "transport", "Thrift")
errc <- thrift.NewTSimpleServer4(
thriftadd.NewAddServiceProcessor(thriftBinding{ctx, e}),
transport,
transportFactory,
protocolFactory,
).Serve()
}()
logger.Log("fatal", <-errc)
}
示例6: 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 := add.NewAddServiceClientFactory(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 "Add":
if flag.NArg()-1 != 2 {
fmt.Fprintln(os.Stderr, "Add requires 2 args")
flag.Usage()
}
argvalue0, err4 := (strconv.ParseInt(flag.Arg(1), 10, 64))
if err4 != nil {
Usage()
return
}
//.........这里部分代码省略.........
示例7: main
func main() {
// Flag domain. Note that gRPC transitively registers flags via its import
// of glog. So, we define a new flag set, to keep those domains distinct.
fs := flag.NewFlagSet("", flag.ExitOnError)
var (
transport = fs.String("transport", "grpc", "http, grpc, netrpc, thrift")
httpAddr = fs.String("http.addr", "localhost:8001", "HTTP (JSON) address")
grpcAddr = fs.String("grpc.addr", "localhost:8002", "gRPC address")
netrpcAddr = fs.String("netrpc.addr", "localhost:8003", "net/rpc address")
thriftAddr = fs.String("thrift.addr", "localhost:8004", "Thrift address")
thriftProtocol = fs.String("thrift.protocol", "binary", "binary, compact, json, simplejson")
thriftBufferSize = fs.Int("thrift.buffer.size", 0, "0 for unbuffered")
thriftFramed = fs.Bool("thrift.framed", false, "true to enable framing")
a = fs.Int64("a", 1, "a value")
b = fs.Int64("b", 2, "b value")
)
flag.Usage = fs.Usage // only show our flags
fs.Parse(os.Args[1:])
log.SetFlags(0)
log.SetOutput(os.Stdout)
var e endpoint.Endpoint
switch *transport {
case "http":
if !strings.HasPrefix(*httpAddr, "http") {
*httpAddr = "http://" + *httpAddr
}
u, err := url.Parse(*httpAddr)
if err != nil {
log.Fatalf("url.Parse: %v", err)
}
if u.Path == "" {
u.Path = "/add"
}
e = httpclient.NewClient("GET", u.String())
case "grpc":
cc, err := grpc.Dial(*grpcAddr)
if err != nil {
log.Fatalf("grpc.Dial: %v", err)
}
e = grpcclient.NewClient(cc)
case "netrpc":
client, err := rpc.DialHTTP("tcp", *netrpcAddr)
if err != nil {
log.Fatalf("rpc.DialHTTP: %v", err)
}
e = netrpcclient.NewClient(client)
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:
log.Fatalf("invalid protocol %q", *thriftProtocol)
}
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 {
log.Fatalf("thrift.NewTSocket: %v", err)
}
transport := transportFactory.GetTransport(transportSocket)
defer transport.Close()
if err := transport.Open(); err != nil {
log.Fatalf("Thrift transport.Open: %v", err)
}
e = thriftclient.NewClient(thriftadd.NewAddServiceClientFactory(transport, protocolFactory))
default:
log.Fatalf("unsupported transport %q", *transport)
}
response, err := e(context.Background(), reqrep.AddRequest{A: *a, B: *b})
if err != nil {
log.Fatalf("when invoking request: %v", err)
}
addResponse, ok := response.(reqrep.AddResponse)
if !ok {
log.Fatalf("when type-asserting response: %v", endpoint.ErrBadCast)
//.........这里部分代码省略.........
示例8: main
//.........这里部分代码省略.........
mux = http.NewServeMux()
sum, concat endpoint.Endpoint
)
sum = makeSumEndpoint(svc)
sum = kitot.TraceServer(tracer, "sum")(sum)
mux.Handle("/sum", httptransport.NewServer(
root,
sum,
server.DecodeSumRequest,
server.EncodeSumResponse,
httptransport.ServerErrorLogger(transportLogger),
httptransport.ServerBefore(kitot.FromHTTPRequest(tracer, "sum", tracingLogger)),
))
concat = makeConcatEndpoint(svc)
concat = kitot.TraceServer(tracer, "concat")(concat)
mux.Handle("/concat", httptransport.NewServer(
root,
concat,
server.DecodeConcatRequest,
server.EncodeConcatResponse,
httptransport.ServerErrorLogger(transportLogger),
httptransport.ServerBefore(kitot.FromHTTPRequest(tracer, "concat", tracingLogger)),
))
transportLogger.Log("addr", *httpAddr)
errc <- http.ListenAndServe(*httpAddr, mux)
}()
// Transport: gRPC
go func() {
transportLogger := log.NewContext(logger).With("transport", "gRPC")
tracingLogger := log.NewContext(transportLogger).With("component", "tracing")
ln, err := net.Listen("tcp", *grpcAddr)
if err != nil {
errc <- err
return
}
s := grpc.NewServer() // uses its own, internal context
pb.RegisterAddServer(s, newGRPCBinding(root, tracer, svc, tracingLogger))
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", "thrift")
transportLogger.Log("addr", *thriftAddr)
errc <- thrift.NewTSimpleServer4(
thriftadd.NewAddServiceProcessor(thriftBinding{svc}),
transport,
transportFactory,
protocolFactory,
).Serve()
}()
logger.Log("fatal", <-errc)
}
示例9: 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 {
//.........这里部分代码省略.........
示例10: 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()
//.........这里部分代码省略.........
示例11: 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 {
//.........这里部分代码省略.........
示例12: main
//.........这里部分代码省略.........
// Mechanical domain.
errc := make(chan error)
ctx := context.Background()
// Interrupt handler.
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
errc <- fmt.Errorf("%s", <-c)
}()
// Debug listener.
go func() {
logger := log.NewContext(logger).With("transport", "debug")
m := http.NewServeMux()
m.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
m.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
m.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
m.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
m.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
m.Handle("/metrics", stdprometheus.Handler())
logger.Log("addr", *debugAddr)
errc <- http.ListenAndServe(*debugAddr, m)
}()
// HTTP transport.
go func() {
logger := log.NewContext(logger).With("transport", "HTTP")
h := addsvc.MakeHTTPHandler(ctx, endpoints, tracer, logger)
logger.Log("addr", *httpAddr)
errc <- http.ListenAndServe(*httpAddr, h)
}()
// gRPC transport.
go func() {
logger := log.NewContext(logger).With("transport", "gRPC")
ln, err := net.Listen("tcp", *grpcAddr)
if err != nil {
errc <- err
return
}
srv := addsvc.MakeGRPCServer(ctx, endpoints, tracer, logger)
s := grpc.NewServer()
pb.RegisterAddServer(s, srv)
logger.Log("addr", *grpcAddr)
errc <- s.Serve(ln)
}()
// Thrift transport.
go func() {
logger := log.NewContext(logger).With("transport", "Thrift")
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
}
logger.Log("addr", *thriftAddr)
errc <- thrift.NewTSimpleServer4(
thriftadd.NewAddServiceProcessor(addsvc.MakeThriftHandler(ctx, endpoints)),
transport,
transportFactory,
protocolFactory,
).Serve()
}()
// Run!
logger.Log("exit", <-errc)
}