blob: 30b5d528429f412029b9a13830a01043cebb2d84 [file] [log] [blame]
Christian Lavoieafc6d8f2011-02-20 02:39:19 +00001package main;
2
3
4/*
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 */
22
23
24import (
25 "flag"
26 "fmt"
27 "os"
28 "thrift"
29)
30
31func Usage() {
32 fmt.Fprint(os.Stderr, "Usage of ", os.Args[0], " <--server | --client>:\n")
33 flag.PrintDefaults()
34 fmt.Fprint(os.Stderr, "\n")
35 os.Exit(0)
36}
37
38func main() {
39 flag.Usage = Usage
40 var client bool
41 var server bool
42 var protocol string
43 var framed bool
44 var useHttp bool
45 var help bool
46
47 flag.BoolVar(&client, "client", false, "Run client")
48 flag.BoolVar(&server, "server", false, "Run server")
49 flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson)")
50 flag.BoolVar(&framed, "framed", false, "Use framed transport")
51 flag.BoolVar(&useHttp, "http", false, "Use http")
52 flag.BoolVar(&help, "help", false, "See usage string")
53 flag.Parse()
54 if help || (client && server) || !(client || server) {
55 fmt.Print("flag.NArg() == ", flag.NArg(), "\n")
56 flag.Usage()
57 }
58 var protocolFactory thrift.TProtocolFactory
59 switch protocol {
60 case "compact":
61 protocolFactory = thrift.NewTCompactProtocolFactory()
62 case "simplejson":
63 protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
64 case "json":
65 protocolFactory = thrift.NewTJSONProtocolFactory()
66 case "binary", "":
67 protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
68 default:
69 fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
70 Usage()
71 os.Exit(1)
72 }
73 transportFactory := thrift.NewTTransportFactory()
74 if framed {
75 transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
76 }
77
78 if(client) {
79 RunClient(transportFactory, protocolFactory)
80 } else if(server) {
81 RunServer(transportFactory, protocolFactory)
82 } else {
83 flag.Usage()
84 }
85 os.Exit(0)
86}