sonr/app/gateway/gateway.go
Prad Nukala 47c3a53080
refactor/internal (#1216)
* refactor: update import paths in gateway handlers

* refactor: remove obsolete devtools Makefile and README

* build: optimize build process for improved efficiency

* refactor: remove obsolete pkl files related to Matrix and Sonr network configurations

* refactor: move embed code to x/dwn/types
2024-12-24 16:10:20 +00:00

34 lines
1.0 KiB
Go

// 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"
"github.com/onsonr/sonr/app/gateway/context"
"github.com/onsonr/sonr/app/gateway/handlers"
"github.com/onsonr/sonr/internal/common"
config "github.com/onsonr/sonr/internal/config/hway"
hwayorm "github.com/onsonr/sonr/internal/database/hwayorm"
)
type Gateway = *echo.Echo
// New returns a new Gateway instance
func New(env config.Hway, ipc common.IPFS, dbq *hwayorm.Queries) (Gateway, error) {
e := echo.New()
// Built-in middleware
e.Use(echomiddleware.Logger())
e.Use(echomiddleware.Recover())
e.IPExtractor = echo.ExtractIPDirect()
e.Use(echoprometheus.NewMiddleware("hway"))
e.Use(context.UseGateway(env, ipc, dbq))
// Register View Handlers
e.HTTPErrorHandler = handlers.ErrorHandler
e.GET("/", handlers.IndexHandler)
handlers.RegisterHandler(e.Group("/register"))
return e, nil
}