-
Notifications
You must be signed in to change notification settings - Fork 70
/
graph_service-remote.go
executable file
·282 lines (275 loc) · 8.14 KB
/
graph_service-remote.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// Autogenerated by Thrift Compiler (facebook)
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
// @generated
package main
import (
"flag"
"fmt"
"math"
"net"
"net/url"
"os"
"strconv"
"strings"
thrift "github.com/facebook/fbthrift/thrift/lib/go/thrift"
"../../github.com/vesoft-inc/nebula-go/v3/nebula/graph"
)
func Usage() {
fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:")
flag.PrintDefaults()
fmt.Fprintln(os.Stderr, "\nFunctions:")
fmt.Fprintln(os.Stderr, " AuthResponse authenticate(string username, string password)")
fmt.Fprintln(os.Stderr, " void signout(i64 sessionId)")
fmt.Fprintln(os.Stderr, " ExecutionResponse execute(i64 sessionId, string stmt)")
fmt.Fprintln(os.Stderr, " ExecutionResponse executeWithParameter(i64 sessionId, string stmt, parameterMap)")
fmt.Fprintln(os.Stderr, " string executeJson(i64 sessionId, string stmt)")
fmt.Fprintln(os.Stderr, " string executeJsonWithParameter(i64 sessionId, string stmt, parameterMap)")
fmt.Fprintln(os.Stderr, " VerifyClientVersionResp verifyClientVersion(VerifyClientVersionReq req)")
fmt.Fprintln(os.Stderr)
os.Exit(0)
}
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.Transport
_ = strconv.Atoi
_ = math.Abs
flag.Usage = Usage
flag.StringVar(&host, "h", "localhost", "Specify host")
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.NewHTTPPostClient(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.NewSocket(thrift.SocketAddr(net.JoinHostPort(host, portStr)))
if err != nil {
fmt.Fprintln(os.Stderr, "error resolving address:", err)
os.Exit(1)
}
if framed {
trans = thrift.NewFramedTransport(trans)
}
}
if err != nil {
fmt.Fprintln(os.Stderr, "Error creating transport", err)
os.Exit(1)
}
defer trans.Close()
var protocolFactory thrift.ProtocolFactory
switch protocol {
case "compact":
protocolFactory = thrift.NewCompactProtocolFactory()
break
case "simplejson":
protocolFactory = thrift.NewSimpleJSONProtocolFactory()
break
case "json":
protocolFactory = thrift.NewJSONProtocolFactory()
break
case "binary", "":
protocolFactory = thrift.NewBinaryProtocolFactoryDefault()
break
default:
fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol)
Usage()
os.Exit(1)
}
client := graph.NewGraphServiceClientFactory(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 "authenticate":
if flag.NArg() - 1 != 2 {
fmt.Fprintln(os.Stderr, "Authenticate requires 2 args")
flag.Usage()
}
argvalue0 := []byte(flag.Arg(1))
value0 := argvalue0
argvalue1 := []byte(flag.Arg(2))
value1 := argvalue1
fmt.Print(client.Authenticate(value0, value1))
fmt.Print("\n")
break
case "signout":
if flag.NArg() - 1 != 1 {
fmt.Fprintln(os.Stderr, "Signout requires 1 args")
flag.Usage()
}
argvalue0, err17 := (strconv.ParseInt(flag.Arg(1), 10, 64))
if err17 != nil {
Usage()
return
}
value0 := argvalue0
fmt.Print(client.Signout(value0))
fmt.Print("\n")
break
case "execute":
if flag.NArg() - 1 != 2 {
fmt.Fprintln(os.Stderr, "Execute requires 2 args")
flag.Usage()
}
argvalue0, err18 := (strconv.ParseInt(flag.Arg(1), 10, 64))
if err18 != nil {
Usage()
return
}
value0 := argvalue0
argvalue1 := []byte(flag.Arg(2))
value1 := argvalue1
fmt.Print(client.Execute(value0, value1))
fmt.Print("\n")
break
case "executeWithParameter":
if flag.NArg() - 1 != 3 {
fmt.Fprintln(os.Stderr, "ExecuteWithParameter requires 3 args")
flag.Usage()
}
argvalue0, err20 := (strconv.ParseInt(flag.Arg(1), 10, 64))
if err20 != nil {
Usage()
return
}
value0 := argvalue0
argvalue1 := []byte(flag.Arg(2))
value1 := argvalue1
arg22 := flag.Arg(3)
mbTrans23 := thrift.NewMemoryBufferLen(len(arg22))
defer mbTrans23.Close()
_, err24 := mbTrans23.WriteString(arg22)
if err24 != nil {
Usage()
return
}
factory25 := thrift.NewSimpleJSONProtocolFactory()
jsProt26 := factory25.GetProtocol(mbTrans23)
containerStruct2 := graph.NewGraphServiceExecuteWithParameterArgs()
err27 := containerStruct2.ReadField3(jsProt26)
if err27 != nil {
Usage()
return
}
argvalue2 := containerStruct2.ParameterMap
value2 := argvalue2
fmt.Print(client.ExecuteWithParameter(value0, value1, value2))
fmt.Print("\n")
break
case "executeJson":
if flag.NArg() - 1 != 2 {
fmt.Fprintln(os.Stderr, "ExecuteJson requires 2 args")
flag.Usage()
}
argvalue0, err28 := (strconv.ParseInt(flag.Arg(1), 10, 64))
if err28 != nil {
Usage()
return
}
value0 := argvalue0
argvalue1 := []byte(flag.Arg(2))
value1 := argvalue1
fmt.Print(client.ExecuteJson(value0, value1))
fmt.Print("\n")
break
case "executeJsonWithParameter":
if flag.NArg() - 1 != 3 {
fmt.Fprintln(os.Stderr, "ExecuteJsonWithParameter requires 3 args")
flag.Usage()
}
argvalue0, err30 := (strconv.ParseInt(flag.Arg(1), 10, 64))
if err30 != nil {
Usage()
return
}
value0 := argvalue0
argvalue1 := []byte(flag.Arg(2))
value1 := argvalue1
arg32 := flag.Arg(3)
mbTrans33 := thrift.NewMemoryBufferLen(len(arg32))
defer mbTrans33.Close()
_, err34 := mbTrans33.WriteString(arg32)
if err34 != nil {
Usage()
return
}
factory35 := thrift.NewSimpleJSONProtocolFactory()
jsProt36 := factory35.GetProtocol(mbTrans33)
containerStruct2 := graph.NewGraphServiceExecuteJsonWithParameterArgs()
err37 := containerStruct2.ReadField3(jsProt36)
if err37 != nil {
Usage()
return
}
argvalue2 := containerStruct2.ParameterMap
value2 := argvalue2
fmt.Print(client.ExecuteJsonWithParameter(value0, value1, value2))
fmt.Print("\n")
break
case "verifyClientVersion":
if flag.NArg() - 1 != 1 {
fmt.Fprintln(os.Stderr, "VerifyClientVersion requires 1 args")
flag.Usage()
}
arg38 := flag.Arg(1)
mbTrans39 := thrift.NewMemoryBufferLen(len(arg38))
defer mbTrans39.Close()
_, err40 := mbTrans39.WriteString(arg38)
if err40 != nil {
Usage()
return
}
factory41 := thrift.NewSimpleJSONProtocolFactory()
jsProt42 := factory41.GetProtocol(mbTrans39)
argvalue0 := graph.NewVerifyClientVersionReq()
err43 := argvalue0.Read(jsProt42)
if err43 != nil {
Usage()
return
}
value0 := argvalue0
fmt.Print(client.VerifyClientVersion(value0))
fmt.Print("\n")
break
case "":
Usage()
break
default:
fmt.Fprintln(os.Stderr, "Invalid function ", cmd)
}
}