This commit is contained in:
mr
2025-04-28 16:17:44 +02:00
parent af6aa9e17f
commit e74f3adcaa
2 changed files with 15 additions and 1 deletions

View File

@@ -54,6 +54,7 @@ func (o *LokiController) GetLogs() {
}
path += "?query={" + strings.Join(query, ", ") + "}&start=" + start + "&end=" + end
resp, err := http.Get(config.GetConfig().LokiUrl + path) // CALL
fmt.Println(resp, path)
if err != nil {
o.Ctx.ResponseWriter.WriteHeader(422)
o.Data["json"] = map[string]string{"error": err.Error()}
@@ -62,7 +63,16 @@ func (o *LokiController) GetLogs() {
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
o.Data["json"] = body
var result map[string]interface{}
// Unmarshal: string → []byte → object
err = json.Unmarshal(body, &result)
if err != nil {
o.Ctx.ResponseWriter.WriteHeader(403)
o.Data["json"] = map[string]string{"error": err.Error()}
o.ServeJSON()
return
}
o.Data["json"] = result
o.ServeJSON()
return
}