golang类型转换循环-apache模块
我正在尝试构造一个Apache模块系统的Go接口。也就是说,我希望能够从Apache模块调用Go函数。这是我的Go文件:golang类型转换循环-apache模块,apache,go,apache-modules,cgo,Apache,Go,Apache Modules,Cgo,我正在尝试构造一个Apache模块系统的Go接口。也就是说,我希望能够从Apache模块调用Go函数。这是我的Go文件: package main // #cgo CFLAGS: -I/usr/include/apache2 -I/usr/include/apr-1.0 // #include <httpd.h> import "C" //export handler func handler(r *C.request_rec) int { ap_set_content_
package main
// #cgo CFLAGS: -I/usr/include/apache2 -I/usr/include/apr-1.0
// #include <httpd.h>
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;
}
第8行是函数“handler”开始的那一行。有什么建议吗
或者,当我使用cgo(go工具cgo mod_frugal.go
)构建时,它根本看不到我的include指令:
/home/vagrant/mod_frugal/src/mod_frugal.go:4:20: fatal error: httpd.h: No such file or directory
// #include <httpd.h>
^
compilation terminated.
也许我需要链接到libhttpd?我只是在互联网上找不到任何关于针对apache2的链接,比如libhttpd
编辑:
请随意跟随对话:
/home/vagrant/mod_frugal/src/mod_frugal.go:4:20: fatal error: httpd.h: No such file or directory
// #include <httpd.h>
^
compilation terminated.
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, "<h1>Hello, world from Go!</h1>")
return OK
}
# _/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)