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

Method handlePutDbConfigFunction

rest/admin_functions_api.go:67–92  ·  view source on GitHub ↗

PUT/DELETE config: a single user function

()

Source from the content-addressed store, hash-verified

65
66// PUT/DELETE config: a single user function
67func (h *handler) handlePutDbConfigFunction() error {
68 functionName := h.PathVar("function")
69 if h.rq.Method != "DELETE" {
70 // PUT:
71 var functionConfig *functions.FunctionConfig
72 if err := h.readJSONInto(&functionConfig); err != nil {
73 return err
74 }
75 return h.mutateDbConfig(func(dbConfig *DbConfig) error {
76 if dbConfig.UserFunctions == nil {
77 dbConfig.UserFunctions = &functions.FunctionsConfig{}
78 }
79 dbConfig.UserFunctions.Definitions[functionName] = functionConfig
80 return nil
81 })
82 } else {
83 // DELETE:
84 return h.mutateDbConfig(func(dbConfig *DbConfig) error {
85 if dbConfig.UserFunctions == nil || dbConfig.UserFunctions.Definitions[functionName] == nil {
86 return base.HTTPErrorf(http.StatusNotFound, "")
87 }
88 delete(dbConfig.UserFunctions.Definitions, functionName)
89 return nil
90 })
91 }
92}

Callers

nothing calls this directly

Calls 4

PathVarMethod · 0.95
readJSONIntoMethod · 0.95
mutateDbConfigMethod · 0.95
HTTPErrorfFunction · 0.92

Tested by

no test coverage detected