Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 1 | /* |
| 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 |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 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 |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | package common |
| 21 | |
| 22 | import ( |
John Boiles | 5785279 | 2018-01-05 14:37:05 -0800 | [diff] [blame] | 23 | "context" |
| 24 | "encoding/hex" |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 25 | "errors" |
| 26 | "fmt" |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 27 | "time" |
Yuxuan 'fishy' Wang | b71f11e | 2021-03-22 15:01:00 -0700 | [diff] [blame] | 28 | |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 29 | "github.com/apache/thrift/lib/go/thrift" |
| 30 | |
Yuxuan 'fishy' Wang | 17373a3 | 2021-08-26 11:04:27 -0700 | [diff] [blame] | 31 | //lint:ignore ST1001 allow dot import here |
Yuxuan 'fishy' Wang | b71f11e | 2021-03-22 15:01:00 -0700 | [diff] [blame] | 32 | . "github.com/apache/thrift/test/go/src/gen/thrifttest" |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | var PrintingHandler = &printingHandler{} |
| 36 | |
| 37 | type printingHandler struct{} |
| 38 | |
| 39 | // Prints "testVoid()" and returns nothing. |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 40 | func (p *printingHandler) TestVoid(ctx context.Context) (err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 41 | fmt.Println("testVoid()") |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | // Prints 'testString("%s")' with thing as '%s' |
| 46 | // @param string thing - the string to print |
| 47 | // @return string - returns the string 'thing' |
| 48 | // |
| 49 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 50 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 51 | func (p *printingHandler) TestString(ctx context.Context, thing string) (r string, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 52 | fmt.Printf("testString(\"%s\")\n", thing) |
| 53 | return thing, nil |
| 54 | } |
| 55 | |
Jens Geyer | fa0796d | 2015-10-16 21:33:39 +0200 | [diff] [blame] | 56 | // Prints 'testBool("%t")' with thing as 'true' or 'false' |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 57 | // @param bool thing - the bool to print |
| 58 | // @return bool - returns the bool 'thing' |
| 59 | // |
| 60 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 61 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 62 | func (p *printingHandler) TestBool(ctx context.Context, thing bool) (r bool, err error) { |
Jens Geyer | fa0796d | 2015-10-16 21:33:39 +0200 | [diff] [blame] | 63 | fmt.Printf("testBool(%t)\n", thing) |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 64 | return thing, nil |
| 65 | } |
| 66 | |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 67 | // Prints 'testByte("%d")' with thing as '%d' |
| 68 | // @param byte thing - the byte to print |
| 69 | // @return byte - returns the byte 'thing' |
| 70 | // |
| 71 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 72 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 73 | func (p *printingHandler) TestByte(ctx context.Context, thing int8) (r int8, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 74 | fmt.Printf("testByte(%d)\n", thing) |
| 75 | return thing, nil |
| 76 | } |
| 77 | |
| 78 | // Prints 'testI32("%d")' with thing as '%d' |
| 79 | // @param i32 thing - the i32 to print |
| 80 | // @return i32 - returns the i32 'thing' |
| 81 | // |
| 82 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 83 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 84 | func (p *printingHandler) TestI32(ctx context.Context, thing int32) (r int32, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 85 | fmt.Printf("testI32(%d)\n", thing) |
| 86 | return thing, nil |
| 87 | } |
| 88 | |
| 89 | // Prints 'testI64("%d")' with thing as '%d' |
| 90 | // @param i64 thing - the i64 to print |
| 91 | // @return i64 - returns the i64 'thing' |
| 92 | // |
| 93 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 94 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 95 | func (p *printingHandler) TestI64(ctx context.Context, thing int64) (r int64, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 96 | fmt.Printf("testI64(%d)\n", thing) |
| 97 | return thing, nil |
| 98 | } |
| 99 | |
| 100 | // Prints 'testDouble("%f")' with thing as '%f' |
| 101 | // @param double thing - the double to print |
| 102 | // @return double - returns the double 'thing' |
| 103 | // |
| 104 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 105 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 106 | func (p *printingHandler) TestDouble(ctx context.Context, thing float64) (r float64, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 107 | fmt.Printf("testDouble(%f)\n", thing) |
| 108 | return thing, nil |
| 109 | } |
| 110 | |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 111 | // Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data |
| 112 | // @param []byte thing - the binary to print |
| 113 | // @return []byte - returns the binary 'thing' |
| 114 | // |
| 115 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 116 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 117 | func (p *printingHandler) TestBinary(ctx context.Context, thing []byte) (r []byte, err error) { |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 118 | fmt.Printf("testBinary(%s)\n", hex.EncodeToString(thing)) |
| 119 | return thing, nil |
| 120 | } |
| 121 | |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 122 | // Prints 'testUuid("%s")' where '%s' is the uuid given. Note that the uuid byte order should be correct. |
| 123 | // @param uuid thing - the uuid to print |
| 124 | // @return uuid - returns the uuid 'thing' |
| 125 | // |
| 126 | // Parameters: |
| 127 | // - Thing |
| 128 | func (p *printingHandler) TestUuid(ctx context.Context, thing thrift.Tuuid) (r thrift.Tuuid, err error) { |
| 129 | fmt.Printf("testUuid(%s)\n", thing.String()) |
| 130 | return thing, nil |
| 131 | } |
| 132 | |
Konrad Grochowski | 3b5dacb | 2014-11-24 10:55:31 +0100 | [diff] [blame] | 133 | // Prints 'testStruct("{%s}")' where thing has been formatted into a string of comma separated values |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 134 | // @param Xtruct thing - the Xtruct to print |
| 135 | // @return Xtruct - returns the Xtruct 'thing' |
| 136 | // |
| 137 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 138 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 139 | func (p *printingHandler) TestStruct(ctx context.Context, thing *Xtruct) (r *Xtruct, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 140 | fmt.Printf("testStruct({\"%s\", %d, %d, %d})\n", thing.StringThing, thing.ByteThing, thing.I32Thing, thing.I64Thing) |
| 141 | return thing, err |
| 142 | } |
| 143 | |
| 144 | // Prints 'testNest("{%s}")' where thing has been formatted into a string of the nested struct |
| 145 | // @param Xtruct2 thing - the Xtruct2 to print |
| 146 | // @return Xtruct2 - returns the Xtruct2 'thing' |
| 147 | // |
| 148 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 149 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 150 | func (p *printingHandler) TestNest(ctx context.Context, nest *Xtruct2) (r *Xtruct2, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 151 | thing := nest.StructThing |
| 152 | fmt.Printf("testNest({%d, {\"%s\", %d, %d, %d}, %d})\n", nest.ByteThing, thing.StringThing, thing.ByteThing, thing.I32Thing, thing.I64Thing, nest.I32Thing) |
| 153 | return nest, nil |
| 154 | } |
| 155 | |
| 156 | // Prints 'testMap("{%s")' where thing has been formatted into a string of 'key => value' pairs |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 157 | // |
| 158 | // separated by commas and new lines |
| 159 | // |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 160 | // @param map<i32,i32> thing - the map<i32,i32> to print |
| 161 | // @return map<i32,i32> - returns the map<i32,i32> 'thing' |
| 162 | // |
| 163 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 164 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 165 | func (p *printingHandler) TestMap(ctx context.Context, thing map[int32]int32) (r map[int32]int32, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 166 | fmt.Printf("testMap({") |
| 167 | first := true |
| 168 | for k, v := range thing { |
| 169 | if first { |
| 170 | first = false |
| 171 | } else { |
| 172 | fmt.Printf(", ") |
| 173 | } |
| 174 | fmt.Printf("%d => %d", k, v) |
| 175 | } |
| 176 | fmt.Printf("})\n") |
| 177 | return thing, nil |
| 178 | } |
| 179 | |
| 180 | // Prints 'testStringMap("{%s}")' where thing has been formatted into a string of 'key => value' pairs |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 181 | // |
| 182 | // separated by commas and new lines |
| 183 | // |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 184 | // @param map<string,string> thing - the map<string,string> to print |
| 185 | // @return map<string,string> - returns the map<string,string> 'thing' |
| 186 | // |
| 187 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 188 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 189 | func (p *printingHandler) TestStringMap(ctx context.Context, thing map[string]string) (r map[string]string, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 190 | fmt.Printf("testStringMap({") |
| 191 | first := true |
| 192 | for k, v := range thing { |
| 193 | if first { |
| 194 | first = false |
| 195 | } else { |
| 196 | fmt.Printf(", ") |
| 197 | } |
| 198 | fmt.Printf("%s => %s", k, v) |
| 199 | } |
| 200 | fmt.Printf("})\n") |
| 201 | return thing, nil |
| 202 | } |
| 203 | |
| 204 | // Prints 'testSet("{%s}")' where thing has been formatted into a string of values |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 205 | // |
| 206 | // separated by commas and new lines |
| 207 | // |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 208 | // @param set<i32> thing - the set<i32> to print |
| 209 | // @return set<i32> - returns the set<i32> 'thing' |
| 210 | // |
| 211 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 212 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 213 | func (p *printingHandler) TestSet(ctx context.Context, thing []int32) (r []int32, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 214 | fmt.Printf("testSet({") |
| 215 | first := true |
Yuxuan 'fishy' Wang | b71f11e | 2021-03-22 15:01:00 -0700 | [diff] [blame] | 216 | for k := range thing { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 217 | if first { |
| 218 | first = false |
| 219 | } else { |
| 220 | fmt.Printf(", ") |
| 221 | } |
| 222 | fmt.Printf("%d", k) |
| 223 | } |
| 224 | fmt.Printf("})\n") |
| 225 | return thing, nil |
| 226 | } |
| 227 | |
| 228 | // Prints 'testList("{%s}")' where thing has been formatted into a string of values |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 229 | // |
| 230 | // separated by commas and new lines |
| 231 | // |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 232 | // @param list<i32> thing - the list<i32> to print |
| 233 | // @return list<i32> - returns the list<i32> 'thing' |
| 234 | // |
| 235 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 236 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 237 | func (p *printingHandler) TestList(ctx context.Context, thing []int32) (r []int32, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 238 | fmt.Printf("testList({") |
| 239 | for i, v := range thing { |
| 240 | if i != 0 { |
| 241 | fmt.Printf(", ") |
| 242 | } |
| 243 | fmt.Printf("%d", v) |
| 244 | } |
| 245 | fmt.Printf("})\n") |
| 246 | return thing, nil |
| 247 | } |
| 248 | |
| 249 | // Prints 'testEnum("%d")' where thing has been formatted into it's numeric value |
| 250 | // @param Numberz thing - the Numberz to print |
| 251 | // @return Numberz - returns the Numberz 'thing' |
| 252 | // |
| 253 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 254 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 255 | func (p *printingHandler) TestEnum(ctx context.Context, thing Numberz) (r Numberz, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 256 | fmt.Printf("testEnum(%d)\n", thing) |
| 257 | return thing, nil |
| 258 | } |
| 259 | |
| 260 | // Prints 'testTypedef("%d")' with thing as '%d' |
| 261 | // @param UserId thing - the UserId to print |
| 262 | // @return UserId - returns the UserId 'thing' |
| 263 | // |
| 264 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 265 | // - Thing |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 266 | func (p *printingHandler) TestTypedef(ctx context.Context, thing UserId) (r UserId, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 267 | fmt.Printf("testTypedef(%d)\n", thing) |
| 268 | return thing, nil |
| 269 | } |
| 270 | |
| 271 | // Prints 'testMapMap("%d")' with hello as '%d' |
| 272 | // @param i32 hello - the i32 to print |
| 273 | // @return map<i32,map<i32,i32>> - returns a dictionary with these values: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 274 | // |
| 275 | // {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, } |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 276 | // |
| 277 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 278 | // - Hello |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 279 | func (p *printingHandler) TestMapMap(ctx context.Context, hello int32) (r map[int32]map[int32]int32, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 280 | fmt.Printf("testMapMap(%d)\n", hello) |
| 281 | |
| 282 | r = map[int32]map[int32]int32{ |
Yuxuan 'fishy' Wang | b71f11e | 2021-03-22 15:01:00 -0700 | [diff] [blame] | 283 | -4: {-4: -4, -3: -3, -2: -2, -1: -1}, |
| 284 | 4: {4: 4, 3: 3, 2: 2, 1: 1}, |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 285 | } |
| 286 | return |
| 287 | } |
| 288 | |
| 289 | // So you think you've got this all worked, out eh? |
| 290 | // |
| 291 | // Creates a the returned map with these values and prints it out: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 292 | // |
| 293 | // { 1 => { 2 => argument, |
| 294 | // 3 => argument, |
| 295 | // }, |
| 296 | // 2 => { 6 => <empty Insanity struct>, }, |
| 297 | // } |
| 298 | // |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 299 | // @return map<UserId, map<Numberz,Insanity>> - a map with the above values |
| 300 | // |
| 301 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 302 | // - Argument |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 303 | func (p *printingHandler) TestInsanity(ctx context.Context, argument *Insanity) (r map[UserId]map[Numberz]*Insanity, err error) { |
Nobuaki Sukegawa | 2fab3de | 2015-08-16 15:42:58 +0900 | [diff] [blame] | 304 | fmt.Printf("testInsanity()\n") |
| 305 | r = make(map[UserId]map[Numberz]*Insanity) |
John Boiles | 5785279 | 2018-01-05 14:37:05 -0800 | [diff] [blame] | 306 | r[1] = map[Numberz]*Insanity{ |
Nobuaki Sukegawa | 2fab3de | 2015-08-16 15:42:58 +0900 | [diff] [blame] | 307 | 2: argument, |
| 308 | 3: argument, |
| 309 | } |
John Boiles | 5785279 | 2018-01-05 14:37:05 -0800 | [diff] [blame] | 310 | r[2] = map[Numberz]*Insanity{ |
Nobuaki Sukegawa | 2fab3de | 2015-08-16 15:42:58 +0900 | [diff] [blame] | 311 | 6: NewInsanity(), |
| 312 | } |
| 313 | return |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | // Prints 'testMulti()' |
| 317 | // @param byte arg0 - |
| 318 | // @param i32 arg1 - |
| 319 | // @param i64 arg2 - |
| 320 | // @param map<i16, string> arg3 - |
| 321 | // @param Numberz arg4 - |
| 322 | // @param UserId arg5 - |
| 323 | // @return Xtruct - returns an Xtruct with StringThing = "Hello2, ByteThing = arg0, I32Thing = arg1 |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 324 | // |
| 325 | // and I64Thing = arg2 |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 326 | // |
| 327 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 328 | // - Arg0 |
| 329 | // - Arg1 |
| 330 | // - Arg2 |
| 331 | // - Arg3 |
| 332 | // - Arg4 |
| 333 | // - Arg5 |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 334 | 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) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 335 | fmt.Printf("testMulti()\n") |
| 336 | r = NewXtruct() |
| 337 | |
| 338 | r.StringThing = "Hello2" |
| 339 | r.ByteThing = arg0 |
| 340 | r.I32Thing = arg1 |
| 341 | r.I64Thing = arg2 |
| 342 | return |
| 343 | } |
| 344 | |
| 345 | // Print 'testException(%s)' with arg as '%s' |
| 346 | // @param string arg - a string indication what type of exception to throw |
| 347 | // if arg == "Xception" throw Xception with errorCode = 1001 and message = arg |
| 348 | // elsen if arg == "TException" throw TException |
| 349 | // else do not throw anything |
| 350 | // |
| 351 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 352 | // - Arg |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 353 | func (p *printingHandler) TestException(ctx context.Context, arg string) (err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 354 | fmt.Printf("testException(%s)\n", arg) |
| 355 | switch arg { |
| 356 | case "Xception": |
| 357 | e := NewXception() |
| 358 | e.ErrorCode = 1001 |
| 359 | e.Message = arg |
| 360 | return e |
| 361 | case "TException": |
Yuxuan 'fishy' Wang | 17373a3 | 2021-08-26 11:04:27 -0700 | [diff] [blame] | 362 | //lint:ignore ST1005 To be consistent with other language libraries. |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 363 | return errors.New("Just TException") |
| 364 | } |
| 365 | return |
| 366 | } |
| 367 | |
| 368 | // Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s' |
| 369 | // @param string arg - a string indication what type of exception to throw |
| 370 | // if arg0 == "Xception" throw Xception with errorCode = 1001 and message = "This is an Xception" |
| 371 | // elsen if arg0 == "Xception2" throw Xception2 with errorCode = 2002 and message = "This is an Xception2" |
| 372 | // else do not throw anything |
| 373 | // @return Xtruct - an Xtruct with StringThing = arg1 |
| 374 | // |
| 375 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 376 | // - Arg0 |
| 377 | // - Arg1 |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 378 | func (p *printingHandler) TestMultiException(ctx context.Context, arg0 string, arg1 string) (r *Xtruct, err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 379 | fmt.Printf("testMultiException(%s, %s)\n", arg0, arg1) |
| 380 | switch arg0 { |
| 381 | |
| 382 | case "Xception": |
| 383 | e := NewXception() |
| 384 | e.ErrorCode = 1001 |
| 385 | e.Message = "This is an Xception" |
| 386 | return nil, e |
| 387 | case "Xception2": |
| 388 | e := NewXception2() |
| 389 | e.ErrorCode = 2002 |
| 390 | e.StructThing = NewXtruct() |
| 391 | e.StructThing.StringThing = "This is an Xception2" |
| 392 | return nil, e |
| 393 | default: |
| 394 | r = NewXtruct() |
| 395 | r.StringThing = arg1 |
| 396 | return |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | // Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d' |
| 401 | // sleep 'secondsToSleep' |
| 402 | // Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d' |
| 403 | // @param i32 secondsToSleep - the number of seconds to sleep |
| 404 | // |
| 405 | // Parameters: |
Yuxuan 'fishy' Wang | 2acfe0f | 2022-10-21 10:27:40 -0700 | [diff] [blame^] | 406 | // - SecondsToSleep |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 407 | func (p *printingHandler) TestOneway(ctx context.Context, secondsToSleep int32) (err error) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 408 | fmt.Printf("testOneway(%d): Sleeping...\n", secondsToSleep) |
| 409 | time.Sleep(time.Second * time.Duration(secondsToSleep)) |
| 410 | fmt.Printf("testOneway(%d): done sleeping!\n", secondsToSleep) |
| 411 | return |
| 412 | } |