2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
31 var PrintingHandler = &printingHandler{}
33 type printingHandler struct{}
35 // Prints "testVoid()" and returns nothing.
36 func (p *printingHandler) TestVoid(ctx context.Context) (err error) {
37 fmt.Println("testVoid()")
41 // Prints 'testString("%s")' with thing as '%s'
42 // @param string thing - the string to print
43 // @return string - returns the string 'thing'
47 func (p *printingHandler) TestString(ctx context.Context, thing string) (r string, err error) {
48 fmt.Printf("testString(\"%s\")\n", thing)
52 // Prints 'testBool("%t")' with thing as 'true' or 'false'
53 // @param bool thing - the bool to print
54 // @return bool - returns the bool 'thing'
58 func (p *printingHandler) TestBool(ctx context.Context, thing bool) (r bool, err error) {
59 fmt.Printf("testBool(%t)\n", thing)
63 // Prints 'testByte("%d")' with thing as '%d'
64 // @param byte thing - the byte to print
65 // @return byte - returns the byte 'thing'
69 func (p *printingHandler) TestByte(ctx context.Context, thing int8) (r int8, err error) {
70 fmt.Printf("testByte(%d)\n", thing)
74 // Prints 'testI32("%d")' with thing as '%d'
75 // @param i32 thing - the i32 to print
76 // @return i32 - returns the i32 'thing'
80 func (p *printingHandler) TestI32(ctx context.Context, thing int32) (r int32, err error) {
81 fmt.Printf("testI32(%d)\n", thing)
85 // Prints 'testI64("%d")' with thing as '%d'
86 // @param i64 thing - the i64 to print
87 // @return i64 - returns the i64 'thing'
91 func (p *printingHandler) TestI64(ctx context.Context, thing int64) (r int64, err error) {
92 fmt.Printf("testI64(%d)\n", thing)
96 // Prints 'testDouble("%f")' with thing as '%f'
97 // @param double thing - the double to print
98 // @return double - returns the double 'thing'
102 func (p *printingHandler) TestDouble(ctx context.Context, thing float64) (r float64, err error) {
103 fmt.Printf("testDouble(%f)\n", thing)
107 // Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data
108 // @param []byte thing - the binary to print
109 // @return []byte - returns the binary 'thing'
113 func (p *printingHandler) TestBinary(ctx context.Context, thing []byte) (r []byte, err error) {
114 fmt.Printf("testBinary(%s)\n", hex.EncodeToString(thing))
118 // Prints 'testStruct("{%s}")' where thing has been formatted into a string of comma separated values
119 // @param Xtruct thing - the Xtruct to print
120 // @return Xtruct - returns the Xtruct 'thing'
124 func (p *printingHandler) TestStruct(ctx context.Context, thing *Xtruct) (r *Xtruct, err error) {
125 fmt.Printf("testStruct({\"%s\", %d, %d, %d})\n", thing.StringThing, thing.ByteThing, thing.I32Thing, thing.I64Thing)
129 // Prints 'testNest("{%s}")' where thing has been formatted into a string of the nested struct
130 // @param Xtruct2 thing - the Xtruct2 to print
131 // @return Xtruct2 - returns the Xtruct2 'thing'
135 func (p *printingHandler) TestNest(ctx context.Context, nest *Xtruct2) (r *Xtruct2, err error) {
136 thing := nest.StructThing
137 fmt.Printf("testNest({%d, {\"%s\", %d, %d, %d}, %d})\n", nest.ByteThing, thing.StringThing, thing.ByteThing, thing.I32Thing, thing.I64Thing, nest.I32Thing)
141 // Prints 'testMap("{%s")' where thing has been formatted into a string of 'key => value' pairs
142 // separated by commas and new lines
143 // @param map<i32,i32> thing - the map<i32,i32> to print
144 // @return map<i32,i32> - returns the map<i32,i32> 'thing'
148 func (p *printingHandler) TestMap(ctx context.Context, thing map[int32]int32) (r map[int32]int32, err error) {
149 fmt.Printf("testMap({")
151 for k, v := range thing {
157 fmt.Printf("%d => %d", k, v)
163 // Prints 'testStringMap("{%s}")' where thing has been formatted into a string of 'key => value' pairs
164 // separated by commas and new lines
165 // @param map<string,string> thing - the map<string,string> to print
166 // @return map<string,string> - returns the map<string,string> 'thing'
170 func (p *printingHandler) TestStringMap(ctx context.Context, thing map[string]string) (r map[string]string, err error) {
171 fmt.Printf("testStringMap({")
173 for k, v := range thing {
179 fmt.Printf("%s => %s", k, v)
185 // Prints 'testSet("{%s}")' where thing has been formatted into a string of values
186 // separated by commas and new lines
187 // @param set<i32> thing - the set<i32> to print
188 // @return set<i32> - returns the set<i32> 'thing'
192 func (p *printingHandler) TestSet(ctx context.Context, thing []int32) (r []int32, err error) {
193 fmt.Printf("testSet({")
195 for k, _ := range thing {
207 // Prints 'testList("{%s}")' where thing has been formatted into a string of values
208 // separated by commas and new lines
209 // @param list<i32> thing - the list<i32> to print
210 // @return list<i32> - returns the list<i32> 'thing'
214 func (p *printingHandler) TestList(ctx context.Context, thing []int32) (r []int32, err error) {
215 fmt.Printf("testList({")
216 for i, v := range thing {
226 // Prints 'testEnum("%d")' where thing has been formatted into it's numeric value
227 // @param Numberz thing - the Numberz to print
228 // @return Numberz - returns the Numberz 'thing'
232 func (p *printingHandler) TestEnum(ctx context.Context, thing Numberz) (r Numberz, err error) {
233 fmt.Printf("testEnum(%d)\n", thing)
237 // Prints 'testTypedef("%d")' with thing as '%d'
238 // @param UserId thing - the UserId to print
239 // @return UserId - returns the UserId 'thing'
243 func (p *printingHandler) TestTypedef(ctx context.Context, thing UserId) (r UserId, err error) {
244 fmt.Printf("testTypedef(%d)\n", thing)
248 // Prints 'testMapMap("%d")' with hello as '%d'
249 // @param i32 hello - the i32 to print
250 // @return map<i32,map<i32,i32>> - returns a dictionary with these values:
251 // {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
255 func (p *printingHandler) TestMapMap(ctx context.Context, hello int32) (r map[int32]map[int32]int32, err error) {
256 fmt.Printf("testMapMap(%d)\n", hello)
258 r = map[int32]map[int32]int32{
259 -4: map[int32]int32{-4: -4, -3: -3, -2: -2, -1: -1},
260 4: map[int32]int32{4: 4, 3: 3, 2: 2, 1: 1},
265 // So you think you've got this all worked, out eh?
267 // Creates a the returned map with these values and prints it out:
268 // { 1 => { 2 => argument,
271 // 2 => { 6 => <empty Insanity struct>, },
273 // @return map<UserId, map<Numberz,Insanity>> - a map with the above values
277 func (p *printingHandler) TestInsanity(ctx context.Context, argument *Insanity) (r map[UserId]map[Numberz]*Insanity, err error) {
278 fmt.Printf("testInsanity()\n")
279 r = make(map[UserId]map[Numberz]*Insanity)
280 r[1] = map[Numberz]*Insanity{
284 r[2] = map[Numberz]*Insanity{
290 // Prints 'testMulti()'
291 // @param byte arg0 -
294 // @param map<i16, string> arg3 -
295 // @param Numberz arg4 -
296 // @param UserId arg5 -
297 // @return Xtruct - returns an Xtruct with StringThing = "Hello2, ByteThing = arg0, I32Thing = arg1
298 // and I64Thing = arg2
307 func (p *printingHandler) TestMulti(ctx context.Context, arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 Numberz, arg5 UserId) (r *Xtruct, err error) {
308 fmt.Printf("testMulti()\n")
311 r.StringThing = "Hello2"
318 // Print 'testException(%s)' with arg as '%s'
319 // @param string arg - a string indication what type of exception to throw
320 // if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
321 // elsen if arg == "TException" throw TException
322 // else do not throw anything
326 func (p *printingHandler) TestException(ctx context.Context, arg string) (err error) {
327 fmt.Printf("testException(%s)\n", arg)
335 return errors.New("Just TException")
340 // Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
341 // @param string arg - a string indication what type of exception to throw
342 // if arg0 == "Xception" throw Xception with errorCode = 1001 and message = "This is an Xception"
343 // elsen if arg0 == "Xception2" throw Xception2 with errorCode = 2002 and message = "This is an Xception2"
344 // else do not throw anything
345 // @return Xtruct - an Xtruct with StringThing = arg1
350 func (p *printingHandler) TestMultiException(ctx context.Context, arg0 string, arg1 string) (r *Xtruct, err error) {
351 fmt.Printf("testMultiException(%s, %s)\n", arg0, arg1)
357 e.Message = "This is an Xception"
362 e.StructThing = NewXtruct()
363 e.StructThing.StringThing = "This is an Xception2"
372 // Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
373 // sleep 'secondsToSleep'
374 // Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
375 // @param i32 secondsToSleep - the number of seconds to sleep
379 func (p *printingHandler) TestOneway(ctx context.Context, secondsToSleep int32) (err error) {
380 fmt.Printf("testOneway(%d): Sleeping...\n", secondsToSleep)
381 time.Sleep(time.Second * time.Duration(secondsToSleep))
382 fmt.Printf("testOneway(%d): done sleeping!\n", secondsToSleep)