cic-custodial/cmd/init_api.go
Mohammed Sohail 611addbf64
feat: add service mode flags, other refactors
* closes #32
* bin can now run in full (default), tasker, api mode
* move logg bootstrpping earlier
* config file loading via flag
* rename service to main
* graceful shutdown now in main and dependant on mode
2022-12-01 14:29:34 +00:00

44 lines
972 B
Go

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