1

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_type(r, "text/html");
    ap_rprintf(r, "Hello, world from Go")
    return OK;
}

ビルドすると ( go build mod_frugal.go)、次のエラーが発生します。

# command-line-arguments
./mod_frugal.go:8:17: type conversion loop at volatile *struct apr_bucket

行 8 は、関数「handler」が始まる行です。助言がありますか?

または、 cgo ( go tool cgo mod_frugal.go) でビルドすると、インクルード ディレクティブがまったく表示されません。

/home/vagrant/mod_frugal/src/mod_frugal.go:4:20: fatal error: httpd.h: No such file or directory
// #include <httpd.h>
                ^
compilation terminated.

「C」を追加したとき。2 つの apache 呼び出しにプレフィックスを付けます。

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)

たぶん、libhttpd に対してリンクする必要がありますか? libhttpdなどのビルドでapache2にリンクすることについて、インターネット上で何も見つけることができません。

編集:

ここでの会話を自由にフォローしてください:

4

0 に答える 0