Advertisement
Guest User

Untitled

a guest
Jan 15th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.80 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "log"
  5.     "net/http"
  6.  
  7.     "github.com/gorilla/mux"
  8.     "github.com/gorilla/rpc"
  9.     "github.com/gorilla/rpc/json"
  10. )
  11.  
  12. type Args struct {
  13.     A, B int
  14. }
  15.  
  16. type Arith int
  17.  
  18. type Result int
  19.  
  20. func (t *Arith) multiply(r *http.Request, args *Args, result *Result) error {
  21.     log.Printf("Multiplying %d with %d\n", args.A, args.B)
  22.     *result = Result(args.A * args.B)
  23.     return nil
  24. }
  25.  
  26. func (t *Arith) Multiply(r *http.Request, args *Args, result *Result) error {
  27.     return t.multiply(r, args, result)
  28. }
  29.  
  30. func main() {
  31.     s := rpc.NewServer()
  32.     s.RegisterCodec(json.NewCodec(), "application/json")
  33.     s.RegisterCodec(json.NewCodec(), "application/json;charset=UTF-8")
  34.     arith := new(Arith)
  35.     s.RegisterService(arith, "")
  36.  
  37.     r := mux.NewRouter()
  38.     r.Handle("/rpc", s)
  39.     http.ListenAndServe(":1234", r)
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement