Last active
October 6, 2015 15:52
-
-
Save hatajoe/47ddd2fd18906689de7d to your computer and use it in GitHub Desktop.
This is not work for error "Go type not supported in export: "
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file: main.go | |
package main | |
import "C" | |
import ( | |
"bitbucket.org/binet/go-ffi/pkg/ffi" | |
"fmt" | |
"net/http" | |
) | |
func main() { | |
lib, err := ffi.NewLibrary("./libs/profile.so") | |
if err != nil { | |
panic(err) | |
} | |
defer lib.Close() | |
// I guess I am wrong type specified, but I have no idea for this line... | |
fn, err := lib.Fct("Profile", ffi.Void, []ffi.Type{ffi.Void}) | |
if err != nil { | |
panic(err) | |
} | |
// execute exported function | |
h := fn(func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "Hello, World") | |
}) | |
http.HandleFunc("/", h.Interface().(http.HandlerFunc)) | |
http.ListenAndServe(":8080", nil) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file: plugins/profile/profile.go | |
// go build -buildmode=c-shared -o ./lib/profile.so ./plugins/profile | |
package main | |
import ( | |
"C" | |
"log" | |
"net/http" | |
"time" | |
) | |
//export Profile | |
func Profile(fn http.HandlerFunc) http.HandlerFunc { | |
return func(w http.ResponseWriter, r *http.Request) { | |
b := time.Now() | |
defer log.Printf("elapsed: %v\n", time.Now().Sub(b)) | |
fn(w, r) | |
} | |
} | |
func init() { | |
log.Println("loaded") | |
} | |
func main() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
here's my environment