1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package dbfunc
- import (
- "fmt"
- "devt.de/krotik/ecal/interpreter"
- "devt.de/krotik/ecal/parser"
- "devt.de/krotik/ecal/util"
- "devt.de/krotik/eliasdb/graph"
- )
- type RaiseGraphEventHandledFunc struct {
- }
- func (f *RaiseGraphEventHandledFunc) Run(instanceID string, vs parser.Scope, is map[string]interface{}, tid uint64, args []interface{}) (interface{}, error) {
- return nil, graph.ErrEventHandled
- }
- func (f *RaiseGraphEventHandledFunc) DocString() (string, error) {
- return "When handling a graph event, notify the GraphManager of EliasDB that no further action is necessary.", nil
- }
- var ErrWebEventHandled = fmt.Errorf("Web event handled")
- type RaiseWebEventHandledFunc struct {
- }
- func (f *RaiseWebEventHandledFunc) Run(instanceID string, vs parser.Scope, is map[string]interface{}, tid uint64, args []interface{}) (interface{}, error) {
- if arglen := len(args); arglen != 1 {
- return nil, fmt.Errorf("Function requires 1 parameter: request response object")
- }
- res := args[0]
- if resMap, ok := res.(map[interface{}]interface{}); !ok {
- return nil, fmt.Errorf("Request response object should be a map")
- } else {
- if _, ok := resMap["status"]; !ok {
- resMap["status"] = 200
- }
- if _, ok := resMap["headers"]; !ok {
- resMap["header"] = map[interface{}]interface{}{
- "Content-Type": "application/json; charset=utf-8",
- "X-Content-Type-Options": "nosniff",
- }
- }
- if _, ok := resMap["body"]; !ok {
- resMap["body"] = map[interface{}]interface{}{}
- }
- }
- erp := is["erp"].(*interpreter.ECALRuntimeProvider)
- node := is["astnode"].(*parser.ASTNode)
- return nil, &util.RuntimeErrorWithDetail{
- RuntimeError: erp.NewRuntimeError(ErrWebEventHandled, "", node).(*util.RuntimeError),
- Environment: vs,
- Data: res,
- }
- }
- func (f *RaiseWebEventHandledFunc) DocString() (string, error) {
- return "When handling a web event, notify the web API of EliasDB that the web request was handled.", nil
- }
|