Skip to content

Commit

Permalink
Simplify JSON Result
Browse files Browse the repository at this point in the history
Instead of manually generating JSON, Gin can automatically generate JSON
results. This is easier and will also generate correct content type
headers.
  • Loading branch information
lkiesow committed Jan 31, 2024
1 parent 81d29bf commit e43fe71
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func setupRouter() *gin.Engine {
var result AgentStateResult
json.Unmarshal([]byte(s), &result)

capturing, _ := json.Marshal(result.Update.State == "capturing")
c.String(http.StatusOK, string(capturing))
c.JSON(http.StatusOK, result.Update.State == "capturing")
})

return r
Expand All @@ -123,6 +122,5 @@ func main() {
return
}
r := setupRouter()
// Listen and Server in 0.0.0.0:8080
r.Run(config.Listen)
}

0 comments on commit e43fe71

Please sign in to comment.