Calls a jsEventFunction returning an interface{}
(ctx context.Context, event Event)
| 141 | |
| 142 | // Calls a jsEventFunction returning an interface{} |
| 143 | func (ef *JSEventFunction) CallFunction(ctx context.Context, event Event) (interface{}, error) { |
| 144 | |
| 145 | var err error |
| 146 | var result interface{} |
| 147 | |
| 148 | // Different events send different parameters |
| 149 | switch event := event.(type) { |
| 150 | |
| 151 | case *DocumentChangeEvent: |
| 152 | result, err = ef.Call(ctx, sgbucket.JSONString(event.DocBytes), sgbucket.JSONString(event.OldDoc)) |
| 153 | case *DBStateChangeEvent: |
| 154 | result, err = ef.Call(ctx, event.Doc) |
| 155 | default: |
| 156 | base.WarnfCtx(ctx, "unknown event %v tried to call function", event.EventType()) |
| 157 | return "", fmt.Errorf("unknown event %v tried to call function", event.EventType()) |
| 158 | } |
| 159 | |
| 160 | if err != nil { |
| 161 | base.WarnfCtx(ctx, "Error calling function - function processing aborted: %v", err) |
| 162 | return "", err |
| 163 | } |
| 164 | |
| 165 | return result, err |
| 166 | } |
| 167 | |
| 168 | // Calls a jsEventFunction returning bool. |
| 169 | func (ef *JSEventFunction) CallValidateFunction(ctx context.Context, event Event) (bool, error) { |
no test coverage detected