MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / CallFunction

Method CallFunction

db/event.go:143–166  ·  view source on GitHub ↗

Calls a jsEventFunction returning an interface{}

(ctx context.Context, event Event)

Source from the content-addressed store, hash-verified

141
142// Calls a jsEventFunction returning an interface{}
143func (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.
169func (ef *JSEventFunction) CallValidateFunction(ctx context.Context, event Event) (bool, error) {

Callers 1

CallValidateFunctionMethod · 0.95

Calls 3

WarnfCtxFunction · 0.92
ErrorfMethod · 0.80
EventTypeMethod · 0.65

Tested by

no test coverage detected