add statistics storage
This commit is contained in:
@@ -3,13 +3,16 @@ package main
|
||||
import (
|
||||
"beadstest/cmd/web/routes"
|
||||
"beadstest/cmd/web/server"
|
||||
"beadstest/internal/models"
|
||||
"beadstest/internal/service"
|
||||
"beadstest/internal/storage"
|
||||
"context"
|
||||
"embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/steveyegge/beads"
|
||||
)
|
||||
|
||||
@@ -27,15 +30,19 @@ func main() {
|
||||
handleError(err, "Error initializing Beads service")
|
||||
defer beadSvc.Close()
|
||||
|
||||
statStore := storage.NewStatisticsStorage("./stats.json")
|
||||
statSvc := service.NewStatisticsService(statStore)
|
||||
statStore := storage.NewJsonStorage("./.pm/stats.json", &models.Statistics{
|
||||
ID: uuid.New(),
|
||||
StartTime: time.Now(),
|
||||
})
|
||||
|
||||
_ = statSvc // To avoid unused variable error; remove if statSvc is used
|
||||
statSvc, err := service.NewStatisticsService(statStore)
|
||||
handleError(err, "Error initializing Statistics service")
|
||||
|
||||
server := server.NewServer(server.Server{
|
||||
Port: 8080,
|
||||
Assets: assets,
|
||||
Service: beadSvc,
|
||||
Port: 8080,
|
||||
Assets: assets,
|
||||
Service: beadSvc,
|
||||
StatisticsService: statSvc,
|
||||
Routes: []server.Route{
|
||||
{Pattern: "/", Component: routes.Index()},
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"beadstest/internal/service"
|
||||
"embed"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -10,10 +11,11 @@ import (
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Port int
|
||||
Assets embed.FS
|
||||
Routes []Route
|
||||
Service beads.Storage
|
||||
Port int
|
||||
Assets embed.FS
|
||||
Routes []Route
|
||||
Service beads.Storage
|
||||
StatisticsService *service.StatisticsService
|
||||
}
|
||||
|
||||
// NewServer creates and configures a new HTTP server instance.
|
||||
|
||||
Reference in New Issue
Block a user