changed the return of POST /loki from bytes[] to map[string]interface{}, now logs are displayed in oc-front
This commit is contained in:
		@@ -27,9 +27,12 @@ type LokiInfo struct {
 | 
			
		||||
// @Success 200 {workspace} models.workspace
 | 
			
		||||
// @router / [post]
 | 
			
		||||
func (o *LokiController) GetLogs() {
 | 
			
		||||
	path := "/loki/api/v1/query_range"
 | 
			
		||||
 | 
			
		||||
	var resp map[string]interface{}
 | 
			
		||||
	json.Unmarshal(o.Ctx.Input.CopyBody(100000), &resp)
 | 
			
		||||
	
 | 
			
		||||
	path := "/loki/api/v1/query_range"
 | 
			
		||||
	
 | 
			
		||||
	if len(resp) > 0 {
 | 
			
		||||
		start := fmt.Sprintf("%v", resp["start"])
 | 
			
		||||
		if len(start) > 10 {
 | 
			
		||||
@@ -53,6 +56,7 @@ func (o *LokiController) GetLogs() {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		path += "?query={" + strings.Join(query, ", ") + "}&start=" + start + "&end=" + end
 | 
			
		||||
 | 
			
		||||
		resp, err := http.Get(config.GetConfig().LokiUrl + path) // CALL
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			o.Ctx.ResponseWriter.WriteHeader(422)
 | 
			
		||||
@@ -62,10 +66,19 @@ func (o *LokiController) GetLogs() {
 | 
			
		||||
		}
 | 
			
		||||
		defer resp.Body.Close()
 | 
			
		||||
		body, _ := io.ReadAll(resp.Body)
 | 
			
		||||
		o.Data["json"] = body
 | 
			
		||||
 
 | 
			
		||||
		var data map[string]interface{}
 | 
			
		||||
		err = json.Unmarshal(body,&data)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			o.Ctx.ResponseWriter.WriteHeader(500)
 | 
			
		||||
			o.Data["json"] = err.Error()
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		o.Data["json"] = data
 | 
			
		||||
		o.ServeJSON()
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	o.Ctx.ResponseWriter.WriteHeader(403)
 | 
			
		||||
	o.Data["json"] = map[string]string{"error": "Query error"}
 | 
			
		||||
	o.ServeJSON()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user