modified: web/assets/css/styles.css
modified: web/components/base/input.templ modified: web/components/base/input_templ.go modified: web/components/base/range.templ modified: web/components/base/range_templ.go modified: web/components/base/select.templ modified: web/components/base/select_templ.go modified: web/components/base/textarea.templ modified: web/components/base/textarea_templ.go modified: web/components/icons.templ modified: web/components/icons_templ.go modified: web/components/issue.templ modified: web/components/issue_templ.go modified: web/components/layout.templ modified: web/components/layout_templ.go new file: web/components/sidebar.templ new file: web/components/sidebar_templ.go new file: web/components/status.templ new file: web/components/status_templ.go modified: web/handler/issues.go new file: web/handler/task.go modified: web/input.css deleted: web/package-lock.json deleted: web/package.json modified: web/routes/layout.templ modified: web/routes/layout_templ.go modified: web/server/routes.go modified: web/server/server.go modified: web/web.go
This commit is contained in:
@@ -4,17 +4,30 @@ import (
|
||||
"context"
|
||||
"embed"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web/handler"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web/server"
|
||||
)
|
||||
|
||||
type WebConfig = service.Config
|
||||
|
||||
type Web struct {
|
||||
feedbackChan chan task.ValidationFeedback
|
||||
quitChan chan bool
|
||||
}
|
||||
|
||||
func NewWeb() *Web {
|
||||
return &Web{}
|
||||
}
|
||||
|
||||
//go:embed assets/*
|
||||
var assets embed.FS
|
||||
|
||||
func Run(ctx context.Context, config WebConfig) error {
|
||||
func (w *Web) Run(ctx context.Context, config WebConfig) error {
|
||||
svc, cleanup, err := service.NewServices(ctx, config)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -22,7 +35,7 @@ func Run(ctx context.Context, config WebConfig) error {
|
||||
|
||||
defer cleanup()
|
||||
|
||||
server := server.NewServer(server.Server{
|
||||
httpServer := server.NewServer(server.Server{
|
||||
Address: config.WebAddress,
|
||||
Assets: assets,
|
||||
Services: svc,
|
||||
@@ -30,9 +43,35 @@ func Run(ctx context.Context, config WebConfig) error {
|
||||
|
||||
fmt.Printf("Starting web server on %s...\n", config.WebAddress)
|
||||
|
||||
if err := server.ListenAndServe(); err != nil {
|
||||
return err
|
||||
serverErr := make(chan error, 1)
|
||||
go func() {
|
||||
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
serverErr <- err
|
||||
}
|
||||
}()
|
||||
|
||||
if w.feedbackChan != nil {
|
||||
go func() {
|
||||
for feedback := range w.feedbackChan {
|
||||
handler.SetTaskFeedback(feedback)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return nil
|
||||
select {
|
||||
case <-w.quitChan:
|
||||
fmt.Println("Task completed! Shutting down server...")
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
return httpServer.Shutdown(shutdownCtx)
|
||||
case err := <-serverErr:
|
||||
return err
|
||||
case <-ctx.Done():
|
||||
return httpServer.Shutdown(context.Background())
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Web) SetChannels(feedbackChan chan task.ValidationFeedback, quitChan chan bool) {
|
||||
w.feedbackChan = feedbackChan
|
||||
w.quitChan = quitChan
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user