mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 13:07:09 +00:00
refactor: migrate config package to pkg directory
This commit is contained in:
parent
0502f52ec0
commit
d667c3c604
@ -4,13 +4,13 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/onsonr/sonr/internal/gateway/config"
|
config "github.com/onsonr/sonr/pkg/config/hway"
|
||||||
"github.com/onsonr/sonr/pkg/database/sessions"
|
"github.com/onsonr/sonr/pkg/database/sessions"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Middleware creates a new session middleware
|
// Middleware creates a new session middleware
|
||||||
func Middleware(db *gorm.DB, env config.Env) echo.MiddlewareFunc {
|
func Middleware(db *gorm.DB, env config.Hway) echo.MiddlewareFunc {
|
||||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
cc := NewHTTPContext(c, db)
|
cc := NewHTTPContext(c, db)
|
||||||
@ -27,7 +27,7 @@ type HTTPContext struct {
|
|||||||
echo.Context
|
echo.Context
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
sess *sessions.Session
|
sess *sessions.Session
|
||||||
env config.Env
|
env config.Hway
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the HTTPContext from the echo context
|
// Get returns the HTTPContext from the echo context
|
||||||
|
@ -3,15 +3,15 @@ package gateway
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/onsonr/sonr/internal/gateway/config"
|
|
||||||
"github.com/onsonr/sonr/internal/gateway/context"
|
"github.com/onsonr/sonr/internal/gateway/context"
|
||||||
"github.com/onsonr/sonr/internal/gateway/handlers/index"
|
"github.com/onsonr/sonr/internal/gateway/handlers/index"
|
||||||
"github.com/onsonr/sonr/internal/gateway/handlers/register"
|
"github.com/onsonr/sonr/internal/gateway/handlers/register"
|
||||||
"github.com/onsonr/sonr/pkg/common/response"
|
"github.com/onsonr/sonr/pkg/common/response"
|
||||||
|
config "github.com/onsonr/sonr/pkg/config/hway"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterRoutes(e *echo.Echo, env config.Env, db *gorm.DB) error {
|
func RegisterRoutes(e *echo.Echo, env config.Hway, db *gorm.DB) error {
|
||||||
// Custom error handler for gateway
|
// Custom error handler for gateway
|
||||||
e.HTTPErrorHandler = response.RedirectOnError("http://localhost:3000")
|
e.HTTPErrorHandler = response.RedirectOnError("http://localhost:3000")
|
||||||
|
|
||||||
|
@ -4,13 +4,13 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/onsonr/sonr/internal/gateway/config"
|
config "github.com/onsonr/sonr/pkg/config/hway"
|
||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewGormDB initializes and returns a configured database connection
|
// NewGormDB initializes and returns a configured database connection
|
||||||
func NewGormDB(env config.Env) (*gorm.DB, error) {
|
func NewGormDB(env config.Hway) (*gorm.DB, error) {
|
||||||
path := formatDBPath(env.GetSqliteFile())
|
path := formatDBPath(env.GetSqliteFile())
|
||||||
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{})
|
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/onsonr/sonr/internal/gateway/config"
|
config "github.com/onsonr/sonr/pkg/config/hway"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ func GetClientConn(c echo.Context) (*grpc.ClientConn, error) {
|
|||||||
return grpcConn, nil
|
return grpcConn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Middleware(env config.Env) echo.MiddlewareFunc {
|
func Middleware(env config.Hway) echo.MiddlewareFunc {
|
||||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
cc := &ClientsContext{Context: c, addr: env.GetSonrGrpcUrl()}
|
cc := &ClientsContext{Context: c, addr: env.GetSonrGrpcUrl()}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user