4 changed files with 74 additions and 0 deletions
@ -0,0 +1,22 @@ |
|||||||
|
package handlers |
||||||
|
|
||||||
|
import ( |
||||||
|
"html/template" |
||||||
|
"net/http" |
||||||
|
) |
||||||
|
|
||||||
|
type ModeHandler struct { |
||||||
|
Tmpl *template.Template |
||||||
|
} |
||||||
|
|
||||||
|
func (m *ModeHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { |
||||||
|
data := struct { |
||||||
|
Title string |
||||||
|
}{ |
||||||
|
Title: "Title", |
||||||
|
} |
||||||
|
|
||||||
|
if err := m.Tmpl.ExecuteTemplate(w, "game-mode.html", data); err != nil { |
||||||
|
http.Error(w, "Template Error", http.StatusInternalServerError) |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,49 @@ |
|||||||
|
package handlers |
||||||
|
|
||||||
|
import ( |
||||||
|
"encoding/json" |
||||||
|
"net/http" |
||||||
|
"systemdesigngame/internal/design" |
||||||
|
) |
||||||
|
|
||||||
|
type SimulationHandler struct{} |
||||||
|
|
||||||
|
type SimulationResponse struct { |
||||||
|
Success bool `json:"success"` |
||||||
|
Metrics map[string]interface{} `json:"metrics,omitempty"` |
||||||
|
Timeline []interface{} `json:"timeline,omitempty"` |
||||||
|
Error string `json:"error,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
func (h *SimulationHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
||||||
|
if r.Method != http.MethodPost { |
||||||
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
var design design.Design |
||||||
|
if err := json.NewDecoder(r.Body).Decode(&design); err != nil { |
||||||
|
http.Error(w, "Invalid design JSON: "+err.Error(), http.StatusBadRequest) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// TODO: Run simulation engine here
|
||||||
|
|
||||||
|
// For now, return a mock successful response but eventually, we want to go to the results page(s)
|
||||||
|
response := SimulationResponse{ |
||||||
|
Success: true, |
||||||
|
Metrics: map[string]interface{}{ |
||||||
|
"throughput": 250, |
||||||
|
"latency_p95": 85, |
||||||
|
"cost_monthly": 120, |
||||||
|
"availability": 99.5, |
||||||
|
}, |
||||||
|
Timeline: []interface{}{}, // Will contain TickSnapshots later
|
||||||
|
} |
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json") |
||||||
|
if err := json.NewEncoder(w).Encode(response); err != nil { |
||||||
|
http.Error(w, "Failed to encode response", http.StatusInternalServerError) |
||||||
|
return |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue