blob: 4b9576eef8f7673b826e9c2e6cea65553d7563ad [file] [log] [blame]
Jens Geyer0e87c462013-06-18 22:25:07 +02001package main
Christian Lavoieafc6d8f2011-02-20 02:39:19 +00002
3/*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
Christian Lavoieafc6d8f2011-02-20 02:39:19 +000022import (
Jens Geyer0e87c462013-06-18 22:25:07 +020023 "flag"
24 "fmt"
25 "git.apache.org/thrift.git/lib/go/thrift"
26 "os"
Christian Lavoieafc6d8f2011-02-20 02:39:19 +000027)
28
29func Usage() {
Jens Geyer0e87c462013-06-18 22:25:07 +020030 fmt.Fprint(os.Stderr, "Usage of ", os.Args[0], ":\n")
31 flag.PrintDefaults()
32 fmt.Fprint(os.Stderr, "\n")
Christian Lavoieafc6d8f2011-02-20 02:39:19 +000033}
34
35func main() {
Jens Geyer0e87c462013-06-18 22:25:07 +020036 flag.Usage = Usage
37 server := flag.Bool("server", false, "Run server")
38 protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, simplejson)")
39 framed := flag.Bool("framed", false, "Use framed transport")
40
41 flag.Parse()
42
43 var protocolFactory thrift.TProtocolFactory
44 switch *protocol {
45 case "compact":
46 protocolFactory = thrift.NewTCompactProtocolFactory()
47 case "simplejson":
48 protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
49 case "json":
50 protocolFactory = thrift.NewTJSONProtocolFactory()
51 case "binary", "":
52 protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
53 default:
54 fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
55 Usage()
56 os.Exit(1)
57 }
58 transportFactory := thrift.NewTTransportFactory()
59 if *framed {
60 transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
61 }
62
63 if *server {
64 if err := runServer(transportFactory, protocolFactory); err != nil {
65 fmt.Println("error running server:", err)
66 }
67 } else {
68 if err := runClient(transportFactory, protocolFactory); err != nil {
69 fmt.Println("error running client:", err)
70 }
71 }
Christian Lavoieafc6d8f2011-02-20 02:39:19 +000072}