grumpyhome / grumpy

Grumpy is a Python to Go source code transcompiler and runtime.
Apache License 2.0
420 stars 18 forks source link

Use python function as go function #13

Open alanjds opened 6 years ago

alanjds commented 6 years ago

google/grumpy#14 opened by @teodor-pripoae on 4 Jan 2017

I'm trying to implement a simple HTTP server, but it seems I can't send a python function as a go function to HandleFunc.

from __go__.net.http import ListenAndServe
from __go__.githubcom.gorilla.mux import NewRouter
from __go__.fmt import Fprintf

def HomeHandler(w, r):
    Fprintf(w, "Hello world")

r = NewRouter()
r.HandleFunc("/", HomeHandler)
ListenAndServe(":8000", r)

I'm receiving this error:

$ cat web.py | make run
TypeError: cannot convert grumpy.Object to func(http.ResponseWriter, *http.Request)
exit status 1
make: *** [run] Error 1
alanjds commented 6 years ago

Comment by trotterdylan Wednesday Jan 04, 2017 at 21:08 GMT


Yeah, this used to work but I think it got removed as part of some other refactoring. I'll spend some time getting it working again.

alanjds commented 6 years ago

Comment by S-YOU Thursday Jan 05, 2017 at 07:42 GMT


I think the real issue is how to convert something(w, r) from python to func(http.ResponseWriter, *http.Request), you might need type annotations like python 3.6 does.