You can use cgo on App Engine Go 1.11.
$ gcloud app deploy --quiet
$ curl -s $(gcloud app browse --service=cgo111 --no-launch-browser)
42
| runtime: go111 | |
| service: cgo111 |
| module cgo111 |
| package main | |
| // typedef int (*intFunc) (); | |
| // | |
| // int | |
| // bridge_int_func(intFunc f) | |
| // { | |
| // return f(); | |
| // } | |
| // | |
| // int fortytwo() | |
| // { | |
| // return 42; | |
| // } | |
| import "C" | |
| import ( | |
| "fmt" | |
| "log" | |
| "net/http" | |
| "os" | |
| ) | |
| func main() { | |
| http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { | |
| f := C.intFunc(C.fortytwo) | |
| w.WriteHeader(http.StatusOK) | |
| w.Write([]byte(fmt.Sprintln(int(C.bridge_int_func(f))))) | |
| }) | |
| log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", os.Getenv("PORT")), nil)) | |
| } |