TinyPHP-FastHTTP
package main
import (
"github.com/kimkit/tinyphp"
_fasthttp "github.com/kimkit/tinyphp-fasthttp"
"github.com/kimkit/tinyphp/std"
"github.com/valyala/fasthttp"
)
var stmts []tinyphp.Stmt
func init() {
_fasthttp.RegisterFastHttp()
_stmts, err := tinyphp.ParseSrc(`
$ctx = get_var0();
$name = $ctx->get("name");
$ctx->write("hello ".($name ? $name : "world"));
`)
if err != nil {
panic(err)
}
stmts = _stmts
}
func main() {
fasthttp.ListenAndServe(":10781", func(ctx *fasthttp.RequestCtx) {
store := tinyphp.NewStore(std.Funcs, std.Methods)
store.SetVar0(_fasthttp.NewCtx(ctx))
if _, err := tinyphp.RunStmts(stmts, store); err != nil {
ctx.Error(err.Error(), 500)
}
})
}