From 4b591f7d11294c9305fc242884ad593e3a221665 Mon Sep 17 00:00:00 2001 From: Simon Dalvai Date: Wed, 27 Mar 2024 16:43:56 +0100 Subject: [PATCH] serve json as file --- src/main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.go b/src/main.go index 94bfc29..7e92ab0 100644 --- a/src/main.go +++ b/src/main.go @@ -69,5 +69,15 @@ func artifact(c *gin.Context) { c.AbortWithError(http.StatusInternalServerError, err) } - c.JSON(http.StatusOK, data) + file, _ := os.Create("report.json") + defer file.Close() + as_json, _ := json.MarshalIndent(data, "", "\t") + file.Write(as_json) + + c.Header("Content-Description", "File Transfer") + c.Header("Content-Transfer-Encoding", "binary") + c.Header("Content-Disposition", "attachment; filename=report.json") + c.Header("Content-Type", "application/octet-stream") + + c.File("report.json") }