2024-12-16 15:29:54 -05:00
|
|
|
// Package gateway provides the default routes for the Sonr hway.
|
|
|
|
|
package gateway
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/labstack/echo-contrib/echoprometheus"
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
|
echomiddleware "github.com/labstack/echo/v4/middleware"
|
2024-12-28 23:53:54 -05:00
|
|
|
"github.com/onsonr/sonr/gateway/context"
|
|
|
|
|
"github.com/onsonr/sonr/gateway/handlers"
|
2024-12-24 11:10:20 -05:00
|
|
|
"github.com/onsonr/sonr/internal/common"
|
2024-12-16 15:29:54 -05:00
|
|
|
config "github.com/onsonr/sonr/internal/config/hway"
|
2024-12-22 17:01:11 -05:00
|
|
|
hwayorm "github.com/onsonr/sonr/internal/database/hwayorm"
|
2024-12-16 15:29:54 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Gateway = *echo.Echo
|
|
|
|
|
|
|
|
|
|
// New returns a new Gateway instance
|
2024-12-18 15:53:45 -05:00
|
|
|
func New(env config.Hway, ipc common.IPFS, dbq *hwayorm.Queries) (Gateway, error) {
|
2024-12-16 15:29:54 -05:00
|
|
|
e := echo.New()
|
|
|
|
|
|
|
|
|
|
// Built-in middleware
|
|
|
|
|
e.Use(echomiddleware.Logger())
|
|
|
|
|
e.Use(echomiddleware.Recover())
|
2024-12-22 17:01:11 -05:00
|
|
|
e.IPExtractor = echo.ExtractIPDirect()
|
|
|
|
|
e.Use(echoprometheus.NewMiddleware("hway"))
|
|
|
|
|
e.Use(context.UseGateway(env, ipc, dbq))
|
2024-12-16 15:29:54 -05:00
|
|
|
|
2024-12-22 17:01:11 -05:00
|
|
|
// Register View Handlers
|
|
|
|
|
e.HTTPErrorHandler = handlers.ErrorHandler
|
|
|
|
|
e.GET("/", handlers.IndexHandler)
|
|
|
|
|
handlers.RegisterHandler(e.Group("/register"))
|
|
|
|
|
return e, nil
|
2024-12-16 15:29:54 -05:00
|
|
|
}
|