-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathapi.go
More file actions
33 lines (25 loc) · 937 Bytes
/
api.go
File metadata and controls
33 lines (25 loc) · 937 Bytes
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
// api.go
package main
import (
"encoding/json"
"net/http"
)
func startServer(graph *CodeGraph) {
http.HandleFunc("/nodes", func(w http.ResponseWriter, r *http.Request) {
// For simplicity, let's return all nodes. You can add query params to filter nodes.
json.NewEncoder(w).Encode(graph.Nodes)
})
http.HandleFunc("/source-sink-analysis", func(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
sourceMethod := query.Get("sourceMethod")
sinkMethod := query.Get("sinkMethod")
if sourceMethod == "" || sinkMethod == "" {
http.Error(w, "sinkMethod and sourceMethod query parameters are required", http.StatusBadRequest)
return
}
result := AnalyzeSourceSinkPatterns(graph, sourceMethod, sinkMethod)
// Return the result as JSON
json.NewEncoder(w).Encode(result)
})
http.ListenAndServe(":8080", nil)
}