Skip to content

Commit

Permalink
Add Content-Length
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-cheperis committed Dec 7, 2023
1 parent 268dbb1 commit ff75191
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"net/http"
"os"
"strconv"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -100,28 +101,38 @@ func main() {

http.HandleFunc("/offers", func(w http.ResponseWriter, r *http.Request) {
// json list of offers
json := offerCache.rawOffersJson(false)
w.Header().Set("Content-Type", "application/json")
w.Write(offerCache.rawOffersJson(false))
w.Header().Set("Content-Length", strconv.Itoa(len(json)))
w.Write(json)
})
http.HandleFunc("/machines", func(w http.ResponseWriter, r *http.Request) {
// json list of machines
json := offerCache.rawOffersJson(true)
w.Header().Set("Content-Type", "application/json")
w.Write(offerCache.rawOffersJson(true))
w.Header().Set("Content-Length", strconv.Itoa(len(json)))
w.Write(json)
})
http.HandleFunc("/hosts", func(w http.ResponseWriter, r *http.Request) {
// json list of hosts
json := offerCache.hostsJson()
w.Header().Set("Content-Type", "application/json")
w.Write(offerCache.hostsJson())
w.Header().Set("Content-Length", strconv.Itoa(len(json)))
w.Write(json)
})
http.HandleFunc("/gpu-stats", func(w http.ResponseWriter, r *http.Request) {
// json gpu stats
json := offerCache.gpuStatsJson()
w.Header().Set("Content-Type", "application/json")
w.Write(offerCache.gpuStatsJson())
w.Header().Set("Content-Length", strconv.Itoa(len(json)))
w.Write(json)
})
http.HandleFunc("/host-map-data", func(w http.ResponseWriter, r *http.Request) {
// json for geomap
json := offerCache.hostMapJson()
w.Header().Set("Content-Type", "application/json")
w.Write(offerCache.hostMapJson())
w.Header().Set("Content-Length", strconv.Itoa(len(json)))
w.Write(json)
})
http.HandleFunc("/metrics/global", func(w http.ResponseWriter, r *http.Request) {
// global stats
Expand Down

0 comments on commit ff75191

Please sign in to comment.