Advertisement
Guest User

Untitled

a guest
Jan 14th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.69 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 main() {
  27.     s := rpc.NewServer()
  28.     s.RegisterCodec(json.NewCodec(), "application/json")
  29.     s.RegisterCodec(json.NewCodec(), "application/json;charset=UTF-8")
  30.     arith := new(Arith)
  31.     s.RegisterService(arith, "")
  32.  
  33.     r := mux.NewRouter()
  34.     r.Handle("/rpc", s)
  35.     http.ListenAndServe(":1234", r)
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement