mirror of
https://github.com/grassrootseconomics/eth-tracker.git
synced 2026-05-17 10:15:21 +02:00
release: v1.0.0
This commit is contained in:
31
internal/api/api.go
Normal file
31
internal/api/api.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/VictoriaMetrics/metrics"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/stats"
|
||||
"github.com/uptrace/bunrouter"
|
||||
)
|
||||
|
||||
func New(statsCollector *stats.Stats) *bunrouter.Router {
|
||||
router := bunrouter.New()
|
||||
|
||||
router.GET("/metrics", metricsHandler())
|
||||
router.GET("/stats", statsHandler(statsCollector))
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
func metricsHandler() bunrouter.HandlerFunc {
|
||||
return func(w http.ResponseWriter, _ bunrouter.Request) error {
|
||||
metrics.WritePrometheus(w, true)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func statsHandler(s *stats.Stats) bunrouter.HandlerFunc {
|
||||
return func(w http.ResponseWriter, _ bunrouter.Request) error {
|
||||
return bunrouter.JSON(w, s.APIStatsResponse())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user