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