Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "log"
- "net/http"
- "github.com/gorilla/mux"
- "github.com/gorilla/rpc"
- "github.com/gorilla/rpc/json"
- )
- type Args struct {
- A, B int
- }
- type Arith int
- type Result int
- func (t *Arith) multiply(r *http.Request, args *Args, result *Result) error {
- log.Printf("Multiplying %d with %d\n", args.A, args.B)
- *result = Result(args.A * args.B)
- return nil
- }
- func (t *Arith) Multiply(r *http.Request, args *Args, result *Result) error {
- return t.multiply(r, args, result)
- }
- func main() {
- s := rpc.NewServer()
- s.RegisterCodec(json.NewCodec(), "application/json")
- s.RegisterCodec(json.NewCodec(), "application/json;charset=UTF-8")
- arith := new(Arith)
- s.RegisterService(arith, "")
- r := mux.NewRouter()
- r.Handle("/rpc", s)
- http.ListenAndServe(":1234", r)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement