/yaegitesting

small repo for testing yaegi interpreter

Primary LanguageGoMIT LicenseMIT

yaegitesting

Small repo for testing yaegi interpreter.

The idea is that we have some user database with decent amount of users in it. Users have some fixed fields like age, gender and some amount of custom fields that are just int32 and each of these has an id.

And then we want to filter these users somehow. And this filtering algorithm can change often.

We can implement it in code or we can ask user of this service to give us filtering algorithm in request.

Ideally we need JIT compiled language for speed, but LUAJIT (lua interpreter) and V8 (JavaScript interpreter) are not very performant because of cgo overhead.

I wanted to try yaegi for this purpose.


File go1_13... has been generated by goexports tool and then manually fixed a bit.


In order to test this, send the code as a body. Using httpie you can do it like this

➜  yaegitesting git:(master) ✗ cat request.txt | http localhost:8080
HTTP/1.1 200 OK
Content-Length: 0
Date: Sun, 27 Oct 2019 14:00:12 GMT

You will get this output:

2019/10/27 17:01:09 100000 userd in db
2019/10/27 17:01:12 read body 'import "fmt"
import "github.com/mkevac/yaegitesting/user"

func filter(u *user.User) bool {
    if u.Age > 30 {
        return false
    }
    return true
}
'
2019/10/27 17:01:12 26073 users left from 100000
2019/10/27 17:01:12 processing took 53.939745ms