blob: fb9545799d1dffcf04d4f52dbe00df9af88edbc7 [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
Yuxuan 'fishy' Wang17373a32021-08-26 11:04:27 -070026 //lint:ignore ST1001 allow dot import here
Yuxuan 'fishy' Wangb71f11e2021-03-22 15:01:00 -070027 . "github.com/apache/thrift/test/go/src/gen/thrifttest"
Jens Geyerf4598682014-05-08 23:18:44 +020028)
29
30var SimpleHandler = &simpleHandler{}
31
32type simpleHandler struct{}
33
34func (p *simpleHandler) TestVoid() (err error) {
35 return nil
36}
37
38func (p *simpleHandler) TestString(thing string) (r string, err error) {
39 return thing, nil
40}
41
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +090042func (p *simpleHandler) TestBool(thing []byte) (r []byte, err error) {
43 return thing, nil
44}
45
Jens Geyerf4598682014-05-08 23:18:44 +020046func (p *simpleHandler) TestByte(thing int8) (r int8, err error) {
47 return thing, nil
48}
49
50func (p *simpleHandler) TestI32(thing int32) (r int32, err error) {
51 return thing, nil
52}
53
54func (p *simpleHandler) TestI64(thing int64) (r int64, err error) {
55 return thing, nil
56}
57
58func (p *simpleHandler) TestDouble(thing float64) (r float64, err error) {
59 return thing, nil
60}
61
Jens Geyer8bcfdd92014-12-14 03:14:26 +010062func (p *simpleHandler) TestBinary(thing []byte) (r []byte, err error) {
63 return thing, nil
64}
65
Jens Geyerf4598682014-05-08 23:18:44 +020066func (p *simpleHandler) TestStruct(thing *Xtruct) (r *Xtruct, err error) {
67 return r, err
68}
69
70func (p *simpleHandler) TestNest(nest *Xtruct2) (r *Xtruct2, err error) {
71 return nest, nil
72}
73
74func (p *simpleHandler) TestMap(thing map[int32]int32) (r map[int32]int32, err error) {
75 return thing, nil
76}
77
78func (p *simpleHandler) TestStringMap(thing map[string]string) (r map[string]string, err error) {
79 return thing, nil
80}
81
D. Can Celasun43fb34d2017-01-15 10:53:19 +010082func (p *simpleHandler) TestSet(thing []int32) (r []int32, err error) {
Jens Geyerf4598682014-05-08 23:18:44 +020083 return thing, nil
84}
85
86func (p *simpleHandler) TestList(thing []int32) (r []int32, err error) {
87 return thing, nil
88}
89
90func (p *simpleHandler) TestEnum(thing Numberz) (r Numberz, err error) {
91 return thing, nil
92}
93
94func (p *simpleHandler) TestTypedef(thing UserId) (r UserId, err error) {
95 return thing, nil
96}
97
98func (p *simpleHandler) TestMapMap(hello int32) (r map[int32]map[int32]int32, err error) {
99
100 r = map[int32]map[int32]int32{
Yuxuan 'fishy' Wangb71f11e2021-03-22 15:01:00 -0700101 -4: {-4: -4, -3: -3, -2: -2, -1: -1},
102 4: {4: 4, 3: 3, 2: 2, 1: 1},
Jens Geyerf4598682014-05-08 23:18:44 +0200103 }
104 return
105}
106
107func (p *simpleHandler) TestInsanity(argument *Insanity) (r map[UserId]map[Numberz]*Insanity, err error) {
Yuxuan 'fishy' Wang17373a32021-08-26 11:04:27 -0700108 //lint:ignore ST1005 To be consistent with other language libraries.
Jens Geyerf4598682014-05-08 23:18:44 +0200109 return nil, errors.New("No Insanity")
110}
111
112func (p *simpleHandler) TestMulti(arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 Numberz, arg5 UserId) (r *Xtruct, err error) {
113 r = NewXtruct()
114
115 r.StringThing = "Hello2"
116 r.ByteThing = arg0
117 r.I32Thing = arg1
118 r.I64Thing = arg2
119 return
120}
121
122func (p *simpleHandler) TestException(arg string) (err error) {
123 switch arg {
124 case "Xception":
125 e := NewXception()
126 e.ErrorCode = 1001
127 e.Message = arg
128 return e
129 case "TException":
Yuxuan 'fishy' Wang17373a32021-08-26 11:04:27 -0700130 //lint:ignore ST1005 To be consistent with other language libraries.
Jens Geyerf4598682014-05-08 23:18:44 +0200131 return errors.New("Just TException")
132 }
133 return
134}
135
136func (p *simpleHandler) TestMultiException(arg0 string, arg1 string) (r *Xtruct, err error) {
137 switch arg0 {
138
139 case "Xception":
140 e := NewXception()
141 e.ErrorCode = 1001
142 e.Message = "This is an Xception"
143 return nil, e
144 case "Xception2":
145 e := NewXception2()
146 e.ErrorCode = 2002
147 e.StructThing.StringThing = "This is an Xception2"
148 return nil, e
149 default:
150 r = NewXtruct()
151 r.StringThing = arg1
152 return
153 }
154}
155
156func (p *simpleHandler) TestOneway(secondsToSleep int32) (err error) {
157 time.Sleep(time.Second * time.Duration(secondsToSleep))
158 return
159}