title: JSON RPC request in Golang with Gorilla/rpc
body: <p>I'm trying to use the <code>Gorilla/rpc</code> package to set up a RPC to receive a request and reply with a response (obviously).</p>
  
  <p>First I'm trying with the example provided with <code>Gorilla/rpc</code></p>
  
  <p>Here's my code:</p>
  
  <pre><code>type HelloArgs struct {
      Who string
  }
  
  type HelloReply struct {
      Message string
  }
  
  type HelloService struct{}
  
  func (h *HelloService) Say(r *http.Request, args *HelloArgs, reply *HelloReply) error {
      reply.Message = "Hello, " + args.Who + "!"
      return nil
  }
  
  func main() {
      r := mux.NewRouter()
  
      jsonRPC := rpc.NewServer()
      jsonCodec := json.NewCodec()
      jsonRPC.RegisterCodec(jsonCodec, "application/json")
      jsonRPC.RegisterCodec(jsonCodec, "application/json; charset=UTF-8") // For firefox 11 and other browsers which append the charset=UTF-8
      jsonRPC.RegisterService(new(HelloService), "")
      r.Handle("/api", jsonRPC)
  
      http.ListenAndServe(":"+port, nil)
  }
  </code></pre>
  
  <p>I have a couple of issues:</p>
  
  <ol>
  <li><p>I'm not sure how I would set a <code>Access-Control-Allow-Origin</code> header like I normally would on a <code>http.ResponseWriter</code> (with a regular webserver) for cross domain requests, as this doesn't take a <code>http.ResponseWriter</code> as an argument.</p></li>
  <li><p>What would I actually send to access the <code>HelloService.Say</code> method? I've tried <code>{ method: "HelloService.Say", params:[{Who: "Me"}]}</code> but I get <code>405 (Method Not Allowed)</code> (not sure if this is because I can't make x-domain requests though?)</p></li>
  </ol>
  
  <p>Any insight greatly appreciated.</p>