title: golang type conversion loop - apache modules
body: <p>I'm trying to construct a Go interface to the Apache module system. I.e. I want to be able to call Go functions from my Apache module. This is my Go file:</p>
  
  <pre><code>package main
  
  // #cgo CFLAGS: -I/usr/include/apache2 -I/usr/include/apr-1.0
  // #include &lt;httpd.h&gt;
  import "C"
  
  //export handler
  func handler(r *C.request_rec) int {
      ap_set_content_type(r, "text/html");
      ap_rprintf(r, "Hello, world from Go")
      return OK;
  }
  </code></pre>
  
  <p>When I build it (<code>go build mod_frugal.go</code>) I get this error:</p>
  
  <pre><code># command-line-arguments
  ./mod_frugal.go:8:17: type conversion loop at volatile *struct apr_bucket
  </code></pre>
  
  <p>Line 8 is the line that function "handler" begins. Any suggestions?</p>
  
  <p>Alternatively, when I build with cgo (<code>go tool cgo mod_frugal.go</code>) it doesn't see my include directives at all:</p>
  
  <pre><code>/home/vagrant/mod_frugal/src/mod_frugal.go:4:20: fatal error: httpd.h: No such file or directory
  // #include &lt;httpd.h&gt;
                  ^
  compilation terminated.
  </code></pre>
  
  <p>When I added the "C." prefix the two apache calls:</p>
  
  <pre><code>package main
  
  // #cgo CFLAGS: -I/usr/include/apache2 -I/usr/include/apr-1.0
  // #include "mod_frugal.h"
  import "C"
  
  //export handler
  func handler(r *C.struct_request_rec) int {
      C.ap_set_content_type(r, "text/html")
      C.ap_rprintf(r, "&lt;h1&gt;Hello, world from Go!&lt;/h1&gt;")
      return OK
  }
  </code></pre>
  
  <p>I get a new error:</p>
  
  <pre><code># _/home/vagrant/mod_frugal/src
  37: error: 'ap_set_content_type' undeclared (first use in this function)
  37: error: 'ap_rprintf' undeclared (first use in this function)
  </code></pre>
  
  <p>Maybe I need to be linking against libhttpd? I just can't find anything on the internet about linking against apache2 for builds including like libhttpd.</p>
  
  <p>EDIT:</p>
  
  <p>Feel free to follow the conversation <a href="https://groups.google.com/d/msg/golang-nuts/ru1_3cz7Hes/jRognWL4zCsJ" rel="nofollow">here</a>:</p>