blob: 971f17eecbc521b2c00f438f7c64a9fb2c24f463 [file] [log] [blame]
Jens Geyerf4598682014-05-08 23:18:44 +02001/*
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
20package common
21
22import (
23 "errors"
Jens Geyerf4598682014-05-08 23:18:44 +020024 "time"
Yuxuan 'fishy' Wangb71f11e2021-03-22 15:01:00 -070025
26 . "github.com/apache/thrift/test/go/src/gen/thrifttest"
Jens Geyerf4598682014-05-08 23:18:44 +020027)
28
29var SimpleHandler = &simpleHandler{}
30
31type simpleHandler struct{}
32
33func (p *simpleHandler) TestVoid() (err error) {
34 return nil
35}
36
37func (p *simpleHandler) TestString(thing string) (r string, err error) {
38 return thing, nil
39}
40
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +090041func (p *simpleHandler) TestBool(thing []byte) (r []byte, err error) {
42 return thing, nil
43}
44
Jens Geyerf4598682014-05-08 23:18:44 +020045func (p *simpleHandler) TestByte(thing int8) (r int8, err error) {
46 return thing, nil
47}
48
49func (p *simpleHandler) TestI32(thing int32) (r int32, err error) {
50 return thing, nil
51}
52
53func (p *simpleHandler) TestI64(thing int64) (r int64, err error) {
54 return thing, nil
55}
56
57func (p *simpleHandler) TestDouble(thing float64) (r float64, err error) {
58 return thing, nil
59}
60
Jens Geyer8bcfdd92014-12-14 03:14:26 +010061func (p *simpleHandler) TestBinary(thing []byte) (r []byte, err error) {
62 return thing, nil
63}
64
Jens Geyerf4598682014-05-08 23:18:44 +020065func (p *simpleHandler) TestStruct(thing *Xtruct) (r *Xtruct, err error) {
66 return r, err
67}
68
69func (p *simpleHandler) TestNest(nest *Xtruct2) (r *Xtruct2, err error) {
70 return nest, nil
71}
72
73func (p *simpleHandler) TestMap(thing map[int32]int32) (r map[int32]int32, err error) {
74 return thing, nil
75}
76
77func (p *simpleHandler) TestStringMap(thing map[string]string) (r map[string]string, err error) {
78 return thing, nil
79}
80
D. Can Celasun43fb34d2017-01-15 10:53:19 +010081func (p *simpleHandler) TestSet(thing []int32) (r []int32, err error) {
Jens Geyerf4598682014-05-08 23:18:44 +020082 return thing, nil
83}
84
85func (p *simpleHandler) TestList(thing []int32) (r []int32, err error) {
86 return thing, nil
87}
88
89func (p *simpleHandler) TestEnum(thing Numberz) (r Numberz, err error) {
90 return thing, nil
91}
92
93func (p *simpleHandler) TestTypedef(thing UserId) (r UserId, err error) {
94 return thing, nil
95}
96
97func (p *simpleHandler) TestMapMap(hello int32) (r map[int32]map[int32]int32, err error) {
98
99 r = map[int32]map[int32]int32{
Yuxuan 'fishy' Wangb71f11e2021-03-22 15:01:00 -0700100 -4: {-4: -4, -3: -3, -2: -2, -1: -1},
101 4: {4: 4, 3: 3, 2: 2, 1: 1},
Jens Geyerf4598682014-05-08 23:18:44 +0200102 }
103 return
104}
105
106func (p *simpleHandler) TestInsanity(argument *Insanity) (r map[UserId]map[Numberz]*Insanity, err error) {
107 return nil, errors.New("No Insanity")
108}
109
110func (p *simpleHandler) TestMulti(arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 Numberz, arg5 UserId) (r *Xtruct, err error) {
111 r = NewXtruct()
112
113 r.StringThing = "Hello2"
114 r.ByteThing = arg0
115 r.I32Thing = arg1
116 r.I64Thing = arg2
117 return
118}
119
120func (p *simpleHandler) TestException(arg string) (err error) {
121 switch arg {
122 case "Xception":
123 e := NewXception()
124 e.ErrorCode = 1001
125 e.Message = arg
126 return e
127 case "TException":
128 return errors.New("Just TException")
129 }
130 return
131}
132
133func (p *simpleHandler) TestMultiException(arg0 string, arg1 string) (r *Xtruct, err error) {
134 switch arg0 {
135
136 case "Xception":
137 e := NewXception()
138 e.ErrorCode = 1001
139 e.Message = "This is an Xception"
140 return nil, e
141 case "Xception2":
142 e := NewXception2()
143 e.ErrorCode = 2002
144 e.StructThing.StringThing = "This is an Xception2"
145 return nil, e
146 default:
147 r = NewXtruct()
148 r.StringThing = arg1
149 return
150 }
151}
152
153func (p *simpleHandler) TestOneway(secondsToSleep int32) (err error) {
154 time.Sleep(time.Second * time.Duration(secondsToSleep))
155 return
156}