Skip to content

Commit

Permalink
serve json as file
Browse files Browse the repository at this point in the history
  • Loading branch information
dulvui committed Mar 27, 2024
1 parent bd5c410 commit 4b591f7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 4b591f7

Please sign in to comment.