Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Distributed-programming/Go/distributed-programming-4.go
Normal file
34
Task/Distributed-programming/Go/distributed-programming-4.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
|
||||
"taxcomputer"
|
||||
)
|
||||
|
||||
type taxServer struct {
|
||||
rate float64
|
||||
}
|
||||
|
||||
func (s *taxServer) Tax(ctx context.Context,
|
||||
amt *taxcomputer.Amount) (*taxcomputer.Amount, error) {
|
||||
if amt.Cents < 0 {
|
||||
return nil, errors.New("Negative amounts not allowed")
|
||||
}
|
||||
return &taxcomputer.Amount{int32(float64(amt.Cents)*s.rate + .5)}, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
listener, err := net.Listen("tcp", ":1234")
|
||||
if err != nil {
|
||||
grpclog.Fatalf(err.Error())
|
||||
}
|
||||
grpcServer := grpc.NewServer()
|
||||
taxcomputer.RegisterTaxComputerServer(grpcServer, &taxServer{.05})
|
||||
grpcServer.Serve(listener)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue