MCPcopy Index your code
hub / github.com/prest/prest / Execute

Method Execute

controllers/script.go:33–57  ·  view source on GitHub ↗

Execute runs a script from the configured queries location.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

31
32// Execute runs a script from the configured queries location.
33func (h *ScriptHandler) Execute(w http.ResponseWriter, r *http.Request) {
34 vars := mux.Vars(r)
35 queriesPath := vars["queriesLocation"]
36 script := vars["script"]
37 database := vars["database"]
38
39 if database == "" {
40 database = h.db.GetDatabase()
41 }
42
43 ctx, cancel := requestContext(r, database)
44 defer cancel()
45
46 result, err := h.ExecuteScriptQuery(r.WithContext(ctx), queriesPath, script)
47 if err != nil {
48 jsonError(w, err.Error(), http.StatusBadRequest)
49 return
50 }
51
52 if r.Method == "GET" && h.cache != nil {
53 h.cache.BuntSet(r.URL.String(), string(result))
54 }
55 //nolint
56 w.Write(result)
57}
58
59// ExecuteScriptQuery runs a script and returns the result bytes.
60func (h *ScriptHandler) ExecuteScriptQuery(rq *http.Request, queriesPath string, script string) ([]byte, error) {

Callers 5

ParseScriptMethod · 0.80
ExecuteFunction · 0.80

Calls 6

ExecuteScriptQueryMethod · 0.95
requestContextFunction · 0.85
jsonErrorFunction · 0.85
StringMethod · 0.80
GetDatabaseMethod · 0.65
BuntSetMethod · 0.65