title: dynamically determine function parameters in Go
body: <p>Is there a way to programmatically determine the parameters (sequence and types thereof) to a function in Go?</p>
  
  <p>I would like to translate an HTTP request into a method/func call dynamically, to avoid having to write duplicative marshaling code (yes I know I'll need to be very careful about what methods I expose and the possible security risks involved). This would only seem to be possible if I can inspect the parameters a function expects, parse the appropriate values from the request and then dynamically call the function (looks like the last step would use reflect.Value.Call - at least that part seems straight forward).</p>
  
  <p>EDIT: The advantage of being able to do this is that you can create a method that is suitable for use directly in Go as well as remotely.  For example, if you have a func like this:</p>
  
  <pre><code>func UpdatePerson(p *Person) error { ... }
  </code></pre>
  
  <p>That obviously is usable in Go; and I want to be able to expose that externally via HTTP as well.</p>
  
  <p>Using json-rpc comes close but looks like it would (in some cases) require some more crufty structures to be used for the i/o on it.</p>
  
  <p>EDIT 2: Basically I have a whole shipload of CRUD to write and I want to just expose parts of the DAO without having to write all this crazy-ass marshaling code to make another layer that deals with the HTTP stuff.  (For some security sensitive things I'll need to write things more carefully, but many of my DAO functions should literally just be callable "directly from the browser" - and also from Go.)  json-rpc meets the first requirement, but not necessarily the second.</p>