Skip to content

Instantly share code, notes, and snippets.

@ijingo
Created November 18, 2016 08:39
Show Gist options
  • Save ijingo/6a4e052534b845e08bbe3f2d5dcaceee to your computer and use it in GitHub Desktop.
Save ijingo/6a4e052534b845e08bbe3f2d5dcaceee to your computer and use it in GitHub Desktop.
package main
import (
"errors"
"log"
"net"
"net/http"
"net/rpc"
"shared"
)
type Arith int
func (t *Arith) Multiply(args *shared.Args, reply *int) error {
*reply = args.A * args.B
return nil
}
func (t *Arith) Divide(args *shared.Args, reply *shared.Quotient) error {
if args.B == 0 {
return errors.New("Divided by zero")
}
reply.Quo = args.A / args.B
reply.Rem = args.A % args.B
return nil
}
func main() {
arith := new(Arith)
server := rpc.NewServer()
server.Register(shared.Arith(arith))
server.HandleHTTP("/", "/debug")
l, e := net.Listen("tcp", "localhost:1234")
if e != nil {
log.Fatal("listen error", e)
}
http.Serve(l, nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment