mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
50 lines
1018 B
Go
50 lines
1018 B
Go
package v2
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/formancehq/ledger/internal/api/backend"
|
|
sharedapi "github.com/formancehq/stack/libs/go-libs/api"
|
|
"github.com/formancehq/stack/libs/go-libs/migrations"
|
|
)
|
|
|
|
type Info struct {
|
|
Name string `json:"name"`
|
|
Storage StorageInfo `json:"storage"`
|
|
}
|
|
|
|
type StorageInfo struct {
|
|
Migrations []migrations.Info `json:"migrations"`
|
|
}
|
|
|
|
func getLedgerInfo(w http.ResponseWriter, r *http.Request) {
|
|
ledger := backend.LedgerFromContext(r.Context())
|
|
|
|
var err error
|
|
res := Info{
|
|
Name: chi.URLParam(r, "ledger"),
|
|
Storage: StorageInfo{},
|
|
}
|
|
res.Storage.Migrations, err = ledger.GetMigrationsInfo(r.Context())
|
|
if err != nil {
|
|
sharedapi.InternalServerError(w, r, err)
|
|
return
|
|
}
|
|
|
|
sharedapi.Ok(w, res)
|
|
}
|
|
|
|
func getStats(w http.ResponseWriter, r *http.Request) {
|
|
l := backend.LedgerFromContext(r.Context())
|
|
|
|
stats, err := l.Stats(r.Context())
|
|
if err != nil {
|
|
sharedapi.InternalServerError(w, r, err)
|
|
return
|
|
}
|
|
|
|
sharedapi.Ok(w, stats)
|
|
}
|