My most recent attempt came up right with what James was talking about. Here is mod_frugal.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ap_provider.h"
#include "httpd.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_request.h"
extern int handler(void*) __asm__ ("frugal2.main.handler");
static int frugal_handler(request_rec* r) {
int status = handler(r);
return status;
}
static void register_hooks(apr_pool_t *pool) {
ap_hook_handler(frugal_handler, NULL, NULL, APR_HOOK_LAST);
}
module AP_MODULE_DECLARE_DATA frugal2_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
register_hooks
};
Here is frugal2.go:
package main
import "unsafe"
//extern ap_set_content_type
func c_ap_set_content_type(r unsafe.Pointer, t []byte)
//extern ap_rprintf
func c_ap_rprintf(r unsafe.Pointer, t []byte)
func handler(r unsafe.Pointer) int {
c_ap_set_content_type(r, []byte("text/html"))
c_ap_rprintf(r, []byte("<h1>Hello, world from Go!</h1>"))
return 0
}
This is my compilation script:
libtool --tag=CC --mode=compile gccgo -c frugal2.go -o frugal2.o -fgo-prefix=frugal2 -static-libgo
apxs -c frugal2.lo mod_frugal2.c
sudo apxs -ai -n frugal2 mod_frugal2.la
And I get no error until I restart apache at which point this comes up:
Output of config test was:
apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/frugal2.load: Cannot load /usr/lib/apache2/modules/mod_frugal2.so into server: /usr/lib/apache2/modules/mod_frugal2.so: undefined symbol: __go_new
Action 'configtest' failed.
So it looks like James was right, until you sent this message. I'll give this a shot! Thanks for the suggestion!