ottoengine

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2015 License: BSD-2-Clause Imports: 12 Imported by: 0

README

ottoengine

A golang module that wraps the Otto JS VM by Robert Krimen to implement dynamic route handlers in the ws web server.

How it works

If you use the command line options -otto=true and -otto-path=SOME_DIRECTORY or set the environment variables WS_OTTO=true and WS_OTTO_PATH then those JavaScript files found in the WS_OTTO_PATH will be used to create route handles in the ws web server.

The return value of the JavaScript files renders as the content body sent back to the web bowser.

Documentation

Overview

Package ottoengine is a module providing a way to define route processing using the Otto JavaScript virutal machine.

Otto is written by Robert Krimen, see https://github.com/robertkrimen/otto Otto Engine is written by Robert Doiel, see https://github.com/rsdoiel/ws

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRoutes

func AddRoutes(programs []Program)

AddRoutes allows a Program structure to fine an approach route handler.

func Engine

func Engine(program Program)

Engine provides the basic service for ws.go to handle JavaScript interactions server side.

func IsHTML

func IsHTML(value otto.Value) bool

IsHTML is a predicate the returns true if the content is HTML otherwise false.

func IsJSON

func IsJSON(value otto.Value) bool

IsJSON is a predicate that returns true if the content is JSON otherwise false.

Types

type Program

type Program struct {
	Route    string
	Filename string
	Source   []byte
	VM       *otto.Otto
	Script   *otto.Script
}

Program keeps track of assigned route, the JS file, the source of the JS file as well as handles for the VM and Script elements in otto.

func Load

func Load(root string) ([]Program, error)

Load evals a string and returns a Program Struct. This is an alternative to reading a file and eval with LoadFile().

func LoadFile

func LoadFile(root string, filename string, fileInfo os.FileInfo, err error) (*Program, error)

LoadFile ingests a JavaScript file and returns a Program struct.

type Response

type Response struct {
	Code    int
	Status  string
	Headers map[string]string //interface{}
	Content string
}

Response sets up the structure for forming HTTP headers for OttoEngine scripts.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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