otto

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2018 License: Apache-2.0 Imports: 39 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertOttoToGo

func ConvertOttoToGo(value interface{}) interface{}

ConvertOttoToGo ...

func GetAuthorization

func GetAuthorization(value otto.Value) (schema.Authorization, error)

GetAuthorization gets Transaction from otto value

func GetBool

func GetBool(value otto.Value) (bool, error)

GetBool gets bool from otto value

func GetInt64

func GetInt64(value otto.Value) (result int64, err error)

GetInt64 gets int64 from otto value

func GetList

func GetList(value otto.Value) ([]interface{}, error)

GetList gets []interface{} from otto value

func GetMap

func GetMap(value otto.Value) (map[string]interface{}, error)

GetMap gets map[string]interface{} from otto value

func GetString

func GetString(value otto.Value) (string, error)

GetString gets string from otto value

func GetStringList

func GetStringList(value otto.Value) ([]string, error)

GetStringList gets []string from otto value

func GetTransaction

func GetTransaction(value otto.Value) (transaction.Transaction, error)

GetTransaction gets Transaction from otto value

func GohanDbCreate

func GohanDbCreate(transaction transaction.Transaction, needCommit bool, schemaID string,
	dataMap map[string]interface{}) (*schema.Resource, error)

GohanDbCreate adds resource to database

func GohanDbDelete

func GohanDbDelete(transaction transaction.Transaction, needCommit bool, schemaID, ID string) error

GohanDbDelete deletes resource from database

func GohanDbFetch

func GohanDbFetch(tx transaction.Transaction, schemaID, ID,
	tenantID string) (*schema.Resource, error)

GohanDbFetch gets resource from database

func GohanDbLockFetch

func GohanDbLockFetch(tx transaction.Transaction, schemaID, ID, tenantID string, policy schema.LockPolicy) (*schema.Resource, error)

GohanDbLockFetch gets resource from database

func GohanDbMakeColumns

func GohanDbMakeColumns(schemaID string) ([]string, error)

GohanDbMakeColumns creates columns for given resource in database

func GohanDbQuery

func GohanDbQuery(transaction transaction.Transaction, needCommit bool, schemaID,
	sqlString string, arguments []interface{}) ([]map[string]interface{}, error)

GohanDbQuery get resources from database with query

func GohanDbStateFetch

func GohanDbStateFetch(tx transaction.Transaction, schemaID, ID,
	tenantID string) (map[string]interface{}, error)

GohanDbStateFetch gets resource's state from database

func GohanDbStateUpdate

func GohanDbStateUpdate(transaction transaction.Transaction, needCommit bool, schemaID string,
	dataMap map[string]interface{}) (*schema.Resource, error)

GohanDbStateUpdate updates resource's state in database

func GohanDbUpdate

func GohanDbUpdate(transaction transaction.Transaction, needCommit bool, schemaID string,
	dataMap map[string]interface{}) (*schema.Resource, error)

GohanDbUpdate updates resource in database

func GohanHTTP

func GohanHTTP(ctx context.Context, method, rawURL string, headers map[string]interface{},
	postData interface{}, opaque bool) (int, http.Header, string, error)

GohanHTTP performs a HTTP request

func GohanModelCreate

func GohanModelCreate(context map[string]interface{}, schemaID string,
	dataMap map[string]interface{}) (interface{}, error)

GohanModelCreate creates gohan resource and running extensions

func GohanModelDelete

func GohanModelDelete(context map[string]interface{}, schemaID string, resourceID string) error

GohanModelDelete deletes gohan resources and running extensions

func GohanModelFetch

func GohanModelFetch(context map[string]interface{}, schemaID string, resourceID string,
	tenantIDs []string) (interface{}, error)

GohanModelFetch fetch gohan resource and running extensions

func GohanModelList

func GohanModelList(context map[string]interface{}, schemaID string,
	filterMap map[string]interface{}) (interface{}, error)

GohanModelList lists gohan resources and running extensions

func GohanModelUpdate

func GohanModelUpdate(context map[string]interface{}, schemaID string, resourceID string, dataMap map[string]interface{}, tenantIDs []string) (interface{}, error)

GohanModelUpdate updates gohan resource and running extensions

func GohanProcessGlobal

func GohanProcessGlobal(name string) map[string]interface{}

GohanProcessGlobal returns an object global for the whole Gohan process - changes to this object will be seen in all environments. Example:

(test_suite1.env1)     var a = gohan_process_global("a");
(test_suite1.env2)     var a = gohan_process_global("a");
(other_test_suite.env) var a = gohan_process_global("a");
(test_suite1.env1)     a.test = 2;
(test_suite1.env2)     a.test; // => 2
(other_test_suite.env) a.test; // => 2

func PushJSLogModule

func PushJSLogModule(env *Environment, newModule string) (restore func())

PushJSLogModule appends newModule to log module in env, returns a function that restores the original value

func RegisterInit

func RegisterInit(init func(env *Environment))

RegisterInit registers init code

func RegisterModule

func RegisterModule(name string, module interface{})

RegisterModule registers modules

func RequireModule

func RequireModule(name string) (interface{}, error)

RequireModule returns module

func ThrowIfHappened

func ThrowIfHappened(call *otto.FunctionCall, err error)

ThrowIfHappened throws an exception with err's message if err happened

func ThrowOtto

func ThrowOtto(call *otto.FunctionCall, exceptionName string, arguments ...interface{})

ThrowOtto throws custom JavaScript exception that will be passed to Otto

func ThrowOttoException

func ThrowOttoException(call *otto.FunctionCall, format string, arguments ...interface{})

ThrowOttoException throws a JavaScript exception that will be passed to Otto

func ThrowWithMessageIfHappened

func ThrowWithMessageIfHappened(call *otto.FunctionCall, err error, format string, arguments ...interface{})

ThrowWithMessageIfHappened throws an exception with the formatted message if err happened

func VerifyCallArguments

func VerifyCallArguments(call *otto.FunctionCall, functionName string, expectedArgumentsCount int)

VerifyCallArguments verify number of calles

Types

type Environment

type Environment struct {
	Name      string
	VM        *motto.Motto
	DataStore db.DB

	Identity middleware.IdentityService
	Sync     sync.Sync
	// contains filtered or unexported fields
}

Environment javascript based environment for gohan extension

func NewEnvironment

func NewEnvironment(name string, dataStore db.DB, identity middleware.IdentityService, sync sync.Sync) *Environment

NewEnvironment create new gohan extension environment based on context

func (*Environment) ClearEnvironment

func (env *Environment) ClearEnvironment()

ClearEnvironment closes sync and db in env

func (*Environment) Clone

func (env *Environment) Clone() ext.Environment

Clone makes clone of the environment

func (*Environment) GetOrCreateTransaction

func (env *Environment) GetOrCreateTransaction(value otto.Value) (transaction.Transaction, bool, error)

GetOrCreateTransaction gets transaction from otto value or creates new is otto value is null

func (*Environment) GohanGlobal

func (env *Environment) GohanGlobal(name string) map[string]interface{}

GohanGlobal returns an object global for the Core this environment was created for - changes to this object will be seen in other such environments (but not in environments for other Core's,

e.g. not for other test suites)

Example:

(test_suite1.env1)     var a = gohan_global("a");
(test_suite1.env2)     var a = gohan_global("a");
(other_test_suite.env) var a = gohan_global("a");
(test_suite1.env1)     a.test = 2;
(test_suite1.env2)     a.test; // => 2
(other_test_suite.env) a.test; // => undefined

func (*Environment) HandleEvent

func (env *Environment) HandleEvent(event string, context map[string]interface{}) (err error)

HandleEvent handles event

func (*Environment) IsEventHandled

func (env *Environment) IsEventHandled(event string, context map[string]interface{}) bool

IsEventHandled returns whether a given event is handled by this environment

func (*Environment) Load

func (env *Environment) Load(source, code string) error

Load loads script for environment

func (*Environment) LoadExtensionsForPath

func (env *Environment) LoadExtensionsForPath(extensions []*schema.Extension, timeLimit time.Duration, timeLimits []*schema.PathEventTimeLimit, path string) error

LoadExtensionsForPath loads extensions for specific path

func (*Environment) RegisterObject

func (env *Environment) RegisterObject(objectID string, object interface{})

RegisterObject register new object for VM

func (*Environment) SetEventTimeLimit

func (env *Environment) SetEventTimeLimit(eventRegex string, timeLimit time.Duration)

SetEventTimeLimit overrides the default time limit for a given event for this environment

func (*Environment) SetUp

func (env *Environment) SetUp()

SetUp initialize environment

type GlobalStore

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

GlobalStore for values living longer that a single extension environment

func NewGlobalStore

func NewGlobalStore() *GlobalStore

NewGlobalStore ...

func (*GlobalStore) Get

func (store *GlobalStore) Get(name string) map[string]interface{}

Get a value registered for name, or, if there is none, register an empty object.

Jump to

Keyboard shortcuts

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