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