fasthttp

package module
v0.0.0-...-b4ea32e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2020 License: MIT Imports: 4 Imported by: 0

README

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)
		}
	})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterFastHttp

func RegisterFastHttp()

Types

type Ctx

type Ctx struct {
	// contains filtered or unexported fields
}

func NewCtx

func NewCtx(ctx *fasthttp.RequestCtx) *Ctx

func (*Ctx) GetRequestCtx

func (ctx *Ctx) GetRequestCtx() *fasthttp.RequestCtx

func (*Ctx) TypeName

func (ctx *Ctx) TypeName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL