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 | |
| 40 | func (p *simpleHandler) TestByte(thing int8) (r int8, err error) { |
| 41 | return thing, nil |
| 42 | } |
| 43 | |
| 44 | func (p *simpleHandler) TestI32(thing int32) (r int32, err error) { |
| 45 | return thing, nil |
| 46 | } |
| 47 | |
| 48 | func (p *simpleHandler) TestI64(thing int64) (r int64, err error) { |
| 49 | return thing, nil |
| 50 | } |
| 51 | |
| 52 | func (p *simpleHandler) TestDouble(thing float64) (r float64, err error) { |
| 53 | return thing, nil |
| 54 | } |
| 55 | |
| 56 | func (p *simpleHandler) TestStruct(thing *Xtruct) (r *Xtruct, err error) { |
| 57 | return r, err |
| 58 | } |
| 59 | |
| 60 | func (p *simpleHandler) TestNest(nest *Xtruct2) (r *Xtruct2, err error) { |
| 61 | return nest, nil |
| 62 | } |
| 63 | |
| 64 | func (p *simpleHandler) TestMap(thing map[int32]int32) (r map[int32]int32, err error) { |
| 65 | return thing, nil |
| 66 | } |
| 67 | |
| 68 | func (p *simpleHandler) TestStringMap(thing map[string]string) (r map[string]string, err error) { |
| 69 | return thing, nil |
| 70 | } |
| 71 | |
| 72 | func (p *simpleHandler) TestSet(thing map[int32]bool) (r map[int32]bool, err error) { |
| 73 | return thing, nil |
| 74 | } |
| 75 | |
| 76 | func (p *simpleHandler) TestList(thing []int32) (r []int32, err error) { |
| 77 | return thing, nil |
| 78 | } |
| 79 | |
| 80 | func (p *simpleHandler) TestEnum(thing Numberz) (r Numberz, err error) { |
| 81 | return thing, nil |
| 82 | } |
| 83 | |
| 84 | func (p *simpleHandler) TestTypedef(thing UserId) (r UserId, err error) { |
| 85 | return thing, nil |
| 86 | } |
| 87 | |
| 88 | func (p *simpleHandler) TestMapMap(hello int32) (r map[int32]map[int32]int32, err error) { |
| 89 | |
| 90 | r = map[int32]map[int32]int32{ |
| 91 | -4: map[int32]int32{-4: -4, -3: -3, -2: -2, -1: -1}, |
| 92 | 4: map[int32]int32{4: 4, 3: 3, 2: 2, 1: 1}, |
| 93 | } |
| 94 | return |
| 95 | } |
| 96 | |
| 97 | func (p *simpleHandler) TestInsanity(argument *Insanity) (r map[UserId]map[Numberz]*Insanity, err error) { |
| 98 | return nil, errors.New("No Insanity") |
| 99 | } |
| 100 | |
| 101 | func (p *simpleHandler) TestMulti(arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 Numberz, arg5 UserId) (r *Xtruct, err error) { |
| 102 | r = NewXtruct() |
| 103 | |
| 104 | r.StringThing = "Hello2" |
| 105 | r.ByteThing = arg0 |
| 106 | r.I32Thing = arg1 |
| 107 | r.I64Thing = arg2 |
| 108 | return |
| 109 | } |
| 110 | |
| 111 | func (p *simpleHandler) TestException(arg string) (err error) { |
| 112 | switch arg { |
| 113 | case "Xception": |
| 114 | e := NewXception() |
| 115 | e.ErrorCode = 1001 |
| 116 | e.Message = arg |
| 117 | return e |
| 118 | case "TException": |
| 119 | return errors.New("Just TException") |
| 120 | } |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | func (p *simpleHandler) TestMultiException(arg0 string, arg1 string) (r *Xtruct, err error) { |
| 125 | switch arg0 { |
| 126 | |
| 127 | case "Xception": |
| 128 | e := NewXception() |
| 129 | e.ErrorCode = 1001 |
| 130 | e.Message = "This is an Xception" |
| 131 | return nil, e |
| 132 | case "Xception2": |
| 133 | e := NewXception2() |
| 134 | e.ErrorCode = 2002 |
| 135 | e.StructThing.StringThing = "This is an Xception2" |
| 136 | return nil, e |
| 137 | default: |
| 138 | r = NewXtruct() |
| 139 | r.StringThing = arg1 |
| 140 | return |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | func (p *simpleHandler) TestOneway(secondsToSleep int32) (err error) { |
| 145 | time.Sleep(time.Second * time.Duration(secondsToSleep)) |
| 146 | return |
| 147 | } |