cic-dw/internal/public/api.go

41 lines
1014 B
Go
Raw Normal View History

2022-05-14 10:15:45 +02:00
package public
import (
batch_balance "github.com/grassrootseconomics/cic-go/batch_balance"
cic_net "github.com/grassrootseconomics/cic-go/net"
2022-05-14 10:15:45 +02:00
"github.com/jackc/pgx/v4/pgxpool"
"github.com/labstack/echo/v4"
"github.com/nleof/goyesql"
)
type api struct {
db *pgxpool.Pool
q goyesql.Queries
bb *batch_balance.BatchBalance
cn *cic_net.CicNet
2022-05-14 10:15:45 +02:00
}
func InitPublicApi(e *echo.Echo, db *pgxpool.Pool, batchBalance *batch_balance.BatchBalance, cicnet *cic_net.CicNet, queries goyesql.Queries) {
2022-05-14 10:15:45 +02:00
g := e.Group("/public")
g.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Set("api", &api{
db: db,
q: queries,
cn: cicnet,
bb: batchBalance,
2022-05-14 10:15:45 +02:00
})
return next(c)
}
})
// TODO: paginate schema validation
2022-05-14 10:15:45 +02:00
g.GET("/balances/:address", handleBalancesQuery)
g.GET("/tokens-count", handleTokensCountQuery)
g.GET("/tokens", handleTokenListQuery)
g.GET("/token/:address", handleTokenInfo)
g.GET("/token-summary/:address", handleTokenSummary)
2022-05-14 10:15:45 +02:00
}