@@ -53,25 +53,52 @@ func (h *GraphHandlers) reload() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetGraph returns the current parsed graph.
|
||||
func (h *GraphHandlers) GetGraph() *graph.Graph {
|
||||
// LoadedGraph returns the current parsed graph.
|
||||
func (h *GraphHandlers) LoadedGraph() *graph.Graph {
|
||||
h.mu.RLock()
|
||||
defer h.mu.RUnlock()
|
||||
return h.loaded
|
||||
}
|
||||
|
||||
// GetYAML returns the raw YAML content.
|
||||
// @Summary Get dependency graph YAML
|
||||
// @Description Returns the service dependency graph as raw YAML text
|
||||
// GetGraph returns the current dependency graph as JSON.
|
||||
// @Summary Get dependency graph
|
||||
// @Description Returns the service dependency graph as JSON
|
||||
// @Tags graph
|
||||
// @Produce plain
|
||||
// @Success 200 {string} string "YAML content"
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]interface{} "Dependency graph"
|
||||
// @Security Bearer
|
||||
// @Router /graph [get]
|
||||
func (h *GraphHandlers) GetYAML(c *gin.Context) {
|
||||
func (h *GraphHandlers) GetGraph(c *gin.Context) {
|
||||
h.mu.RLock()
|
||||
defer h.mu.RUnlock()
|
||||
c.Data(http.StatusOK, "text/yaml", h.yamlData)
|
||||
|
||||
g := h.loaded
|
||||
if g == nil {
|
||||
c.JSON(http.StatusOK, gin.H{"nodes": map[string]interface{}{}})
|
||||
return
|
||||
}
|
||||
|
||||
nodes := make(map[string]interface{})
|
||||
for _, node := range g.Nodes() {
|
||||
services := make(map[string]interface{})
|
||||
for _, svc := range node.Services {
|
||||
deps := make([]map[string]interface{}, 0)
|
||||
for _, dep := range svc.Dependencies {
|
||||
deps = append(deps, map[string]interface{}{
|
||||
"target": dep.Target,
|
||||
"condition": dep.Condition,
|
||||
})
|
||||
}
|
||||
services[svc.Name] = map[string]interface{}{
|
||||
"dependencies": deps,
|
||||
}
|
||||
}
|
||||
nodes[node.ID] = map[string]interface{}{
|
||||
"services": services,
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"nodes": nodes})
|
||||
}
|
||||
|
||||
// UpdateYAML updates the graph from new YAML text.
|
||||
|
||||
Reference in New Issue
Block a user