1 // Autogenerated by Thrift Compiler (1.0.0-dev)
2 // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
16 "github.com/apache/thrift/lib/go/thrift"
17 "github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc"
22 fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:")
24 fmt.Fprintln(os.Stderr, "\nFunctions:")
25 fmt.Fprintln(os.Stderr, " SumReply Sum(i64 a, i64 b)")
26 fmt.Fprintln(os.Stderr, " ConcatReply Concat(string a, string b)")
27 fmt.Fprintln(os.Stderr)
40 var trans thrift.TTransport
44 flag.StringVar(&host, "h", "localhost", "Specify host and port")
45 flag.IntVar(&port, "p", 9090, "Specify port")
46 flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)")
47 flag.StringVar(&urlString, "u", "", "Specify the url")
48 flag.BoolVar(&framed, "framed", false, "Use framed transport")
49 flag.BoolVar(&useHttp, "http", false, "Use http")
52 if len(urlString) > 0 {
53 parsedUrl, err := url.Parse(urlString)
55 fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
59 useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http"
61 _, err := url.Parse(fmt.Sprint("http://", host, ":", port))
63 fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
71 trans, err = thrift.NewTHttpClient(parsedUrl.String())
73 portStr := fmt.Sprint(port)
74 if strings.Contains(host, ":") {
75 host, portStr, err = net.SplitHostPort(host)
77 fmt.Fprintln(os.Stderr, "error with host:", err)
81 trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr))
83 fmt.Fprintln(os.Stderr, "error resolving address:", err)
87 trans = thrift.NewTFramedTransport(trans)
91 fmt.Fprintln(os.Stderr, "Error creating transport", err)
95 var protocolFactory thrift.TProtocolFactory
98 protocolFactory = thrift.NewTCompactProtocolFactory()
101 protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
104 protocolFactory = thrift.NewTJSONProtocolFactory()
107 protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
110 fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol)
114 client := addsvc.NewAddServiceClientFactory(trans, protocolFactory)
115 if err := trans.Open(); err != nil {
116 fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
122 if flag.NArg() - 1 != 2 {
123 fmt.Fprintln(os.Stderr, "Sum requires 2 args")
126 argvalue0, err6 := (strconv.ParseInt(flag.Arg(1), 10, 64))
132 argvalue1, err7 := (strconv.ParseInt(flag.Arg(2), 10, 64))
138 fmt.Print(client.Sum(context.Background(), value0, value1))
142 if flag.NArg() - 1 != 2 {
143 fmt.Fprintln(os.Stderr, "Concat requires 2 args")
146 argvalue0 := flag.Arg(1)
148 argvalue1 := flag.Arg(2)
150 fmt.Print(client.Concat(context.Background(), value0, value1))
157 fmt.Fprintln(os.Stderr, "Invalid function ", cmd)