refactor to use app package instead of service
refactor app to be composable
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/internal/app"
|
||||
"github.com/donseba/go-htmx"
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@ const (
|
||||
htmxKey contextKey = "htmx"
|
||||
)
|
||||
|
||||
func AppMiddleware(app *service.App) func(http.Handler) http.Handler {
|
||||
func AppMiddleware(app *app.App) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), appKey, app)
|
||||
@@ -33,8 +33,8 @@ func HTMXMiddleware(next http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
func App(r *http.Request) *service.App {
|
||||
return r.Context().Value(appKey).(*service.App)
|
||||
func App(r *http.Request) *app.App {
|
||||
return r.Context().Value(appKey).(*app.App)
|
||||
}
|
||||
|
||||
func HTMX(r *http.Request) *htmx.Handler {
|
||||
|
||||
@@ -5,13 +5,13 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/internal/app"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Address string
|
||||
Assets embed.FS
|
||||
App *service.App
|
||||
App *app.App
|
||||
}
|
||||
|
||||
// NewServer creates and configures a new HTTP server instance.
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/app"
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/internal/utils"
|
||||
"github.com/LazyBachelor/LazyPM/internal/utils/browser"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web/handler"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web/server"
|
||||
)
|
||||
@@ -32,7 +32,7 @@ func New() *Web {
|
||||
var assets embed.FS
|
||||
|
||||
func (w *Web) Run(ctx context.Context, config Config) error {
|
||||
app, cleanup, err := service.NewApp(ctx, config)
|
||||
app, cleanup, err := app.New(ctx, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func (w *Web) Run(ctx context.Context, config Config) error {
|
||||
address = "http://localhost" + address
|
||||
}
|
||||
|
||||
err = utils.OpenBrowser(address)
|
||||
err = browser.Open(address)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open browser: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user