Created
November 18, 2016 08:39
-
-
Save ijingo/6a4e052534b845e08bbe3f2d5dcaceee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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