4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
30 type CalculatorHandler struct {
31 log map[int]*shared.SharedStruct
34 func NewCalculatorHandler() *CalculatorHandler {
35 return &CalculatorHandler{log: make(map[int]*shared.SharedStruct)}
38 func (p *CalculatorHandler) Ping(ctx context.Context) (err error) {
43 func (p *CalculatorHandler) Add(ctx context.Context, num1 int32, num2 int32) (retval17 int32, err error) {
44 fmt.Print("add(", num1, ",", num2, ")\n")
45 return num1 + num2, nil
48 func (p *CalculatorHandler) Calculate(ctx context.Context, logid int32, w *tutorial.Work) (val int32, err error) {
49 fmt.Print("calculate(", logid, ", {", w.Op, ",", w.Num1, ",", w.Num2, "})\n")
51 case tutorial.Operation_ADD:
54 case tutorial.Operation_SUBTRACT:
57 case tutorial.Operation_MULTIPLY:
60 case tutorial.Operation_DIVIDE:
62 ouch := tutorial.NewInvalidOperation()
63 ouch.WhatOp = int32(w.Op)
64 ouch.Why = "Cannot divide by 0"
71 ouch := tutorial.NewInvalidOperation()
72 ouch.WhatOp = int32(w.Op)
73 ouch.Why = "Unknown operation"
77 entry := shared.NewSharedStruct()
79 entry.Value = strconv.Itoa(int(val))
82 oldvalue, exists := p.log[k]
84 fmt.Print("Replacing ", oldvalue, " with ", entry, " for key ", k, "\n")
86 fmt.Print("Adding ", entry, " for key ", k, "\n")
93 func (p *CalculatorHandler) GetStruct(ctx context.Context, key int32) (*shared.SharedStruct, error) {
94 fmt.Print("getStruct(", key, ")\n")
95 v, _ := p.log[int(key)]
99 func (p *CalculatorHandler) Zip(ctx context.Context) (err error) {