-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.go
More file actions
49 lines (40 loc) · 1.05 KB
/
handler.go
File metadata and controls
49 lines (40 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package http
import (
"context"
"github.com/google/uuid"
"github.com/polyxia-org/agent/internal/api"
"github.com/polyxia-org/agent/internal/runtime"
"net/http"
)
func (s *server) invokeHandler(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(context.Background(), "iid", uuid.New().String())
invokeRequest, err := parseRequestBody[api.InvokeRequest](r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
// TODO: message
}
// Validate the invocation request DTO
if err := invokeRequest.Validate(); err != nil {
s.logger.Error(err)
w.WriteHeader(http.StatusBadRequest)
return
// TODO: message
}
// Parse query arguments into runtime.FnVars
params := runtime.FnParams{}
for k := range r.URL.Query() {
params[k] = r.URL.Query().Get(k)
}
result, err := s.ex.Invoke(ctx, &runtime.FnInvocation{
CodeURL: invokeRequest.Code,
Runtime: invokeRequest.Runtime,
Params: params,
})
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
// TODO: message
return
}
s.JSONResponse(w, result)
}