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

Method handleFunctionCall

rest/functions_api.go:29–57  ·  view source on GitHub ↗

FUNCTIONS: HTTP handler for GET or POST `/$db/_function/$name`

()

Source from the content-addressed store, hash-verified

27
28// HTTP handler for GET or POST `/$db/_function/$name`
29func (h *handler) handleFunctionCall() error {
30 var maxRequestSize *int
31 if h.db.Options.UserFunctions != nil {
32 maxRequestSize = h.db.Options.UserFunctions.MaxRequestSize
33 }
34 fnName, fnParams, err := h.getFunctionArgs(maxRequestSize)
35 if err != nil {
36 return err
37 }
38 canMutate := h.rq.Method != "GET"
39
40 return db.WithTimeout(h.ctx(), h.db.UserFunctionTimeout, func(ctx context.Context) error {
41 fn, err := h.db.GetUserFunction(ctx, fnName, fnParams, canMutate)
42 if err != nil {
43 return err
44 } else if rows, err := fn.Iterate(); err != nil {
45 return err
46 } else if rows != nil {
47 return h.writeQueryRows(rows)
48 } else {
49 // Write the single result to the response:
50 result, err := fn.Run(ctx)
51 if err == nil {
52 h.writeJSON(result)
53 }
54 return err
55 }
56 })
57}
58
59// Subroutine for reading function name and arguments from a request
60func (h *handler) getFunctionArgs(maxSize *int) (string, map[string]interface{}, error) {

Callers

nothing calls this directly

Calls 8

getFunctionArgsMethod · 0.95
ctxMethod · 0.95
writeQueryRowsMethod · 0.95
writeJSONMethod · 0.95
WithTimeoutFunction · 0.92
GetUserFunctionMethod · 0.80
IterateMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected