gluapp: a4.io/gluapp Index | Files | Directories

package gluapp

import "a4.io/gluapp"

Index

Package Files

app.go gluapp.go http.go json.go request.go response.go router.go template.go

func Exec Uses

func Exec(conf *Config, code string, w http.ResponseWriter, r *http.Request) error

Exec run the code as a Lua script

func SetupGlue Uses

func SetupGlue(L *lua.LState, conf *Config, w http.ResponseWriter, r *http.Request) error

SetupGlue setup the "glue"/std lib for use outside of gluapp

type App Uses

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

App represents a Lua app

func NewApp Uses

func NewApp(conf *Config) (*App, error)

func (*App) Exec Uses

func (a *App) Exec(w http.ResponseWriter, r *http.Request) (*Response, error)

Exec executes the app in the given context, but it does not write the output to the `http.ResponseWriter`, you need to call `Response.WriteTo(w)` manually.

Most of the time, you should use `App` as a `http.HandlerFunc` (or call `App.ServeHTTP` manually).

func (*App) ServeHTTP Uses

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the `http.HandlerFunc` interface.

type Config Uses

type Config struct {
    // Path for looking up resources (Lua files, templates, public assets)
    Path string

    // Define the app entrypoint, default to `app.lua` (only valid for apps)
    Entrypoint string

    // HTTP client, if not set, `http.DefaultClient` will be used
    Client *http.Client

    // Hook for adding/setting additional modules/global variables
    SetupState func(L *lua.LState, w http.ResponseWriter, r *http.Request) error

    // Hook executed just after the script execution, just before the request is written
    AfterScriptExecHook func(L *lua.LState) error

    // Hook for custom `log` backend, defautl to `fmt.Println`
    LogHook func(logLine string) error

    // Stack trace will be displayed in debug mode
    Debug bool

    TemplateFuncMap template.FuncMap
}

Config represents an app configuration

type Response Uses

type Response struct {
    Body       []byte
    Header     http.Header
    StatusCode int
    // contains filtered or unexported fields
}

Response represents the HTTP response

func (*Response) WriteTo Uses

func (resp *Response) WriteTo(w http.ResponseWriter)

WriteTo dumps the respons to the actual response.

Directories

PathSynopsis
utilpackage util that regroups multiple useful Lua modules.

Package gluapp imports 23 packages (graph) and is imported by 2 packages. Updated 2020-04-13. Refresh now. Tools for package owners.