2022-11-30 10:51:24 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/arl/statsviz"
|
2022-11-30 16:18:01 +01:00
|
|
|
"github.com/go-playground/validator"
|
2022-11-30 10:51:24 +01:00
|
|
|
"github.com/grassrootseconomics/cic-custodial/internal/api"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
func initApiServer() *echo.Echo {
|
2022-12-01 15:29:34 +01:00
|
|
|
lo.Debug("bootstrapping api server")
|
2022-11-30 10:51:24 +01:00
|
|
|
server := echo.New()
|
|
|
|
server.HideBanner = true
|
|
|
|
server.HidePort = true
|
|
|
|
|
|
|
|
if ko.Bool("service.statsviz_debug") {
|
2022-12-01 15:29:34 +01:00
|
|
|
lo.Debug("Starting stats_viz at /debug/statsviz")
|
2022-11-30 10:51:24 +01:00
|
|
|
statsVizMux := http.NewServeMux()
|
|
|
|
_ = statsviz.Register(statsVizMux)
|
|
|
|
server.GET("/debug/statsviz/", echo.WrapHandler(statsVizMux))
|
|
|
|
server.GET("/debug/statsviz/*", echo.WrapHandler(statsVizMux))
|
|
|
|
}
|
|
|
|
|
2022-11-30 16:18:01 +01:00
|
|
|
server.Validator = &api.CustomValidator{
|
|
|
|
Validator: validator.New(),
|
|
|
|
}
|
|
|
|
|
2022-11-30 10:51:24 +01:00
|
|
|
apiRoute := server.Group("/api")
|
|
|
|
|
2022-11-30 16:18:01 +01:00
|
|
|
apiRoute.POST("/register", api.RegistrationHandler(
|
2022-11-30 10:51:24 +01:00
|
|
|
taskerClient,
|
|
|
|
postgresKeystore,
|
|
|
|
))
|
|
|
|
|
2022-11-30 16:18:01 +01:00
|
|
|
apiRoute.POST("/transfer", api.TransferHandler(
|
|
|
|
taskerClient,
|
|
|
|
))
|
|
|
|
|
2022-12-01 15:29:34 +01:00
|
|
|
lo.Debug("Registered all api handlers")
|
2022-11-30 10:51:24 +01:00
|
|
|
return server
|
|
|
|
}
|