feat: login service and implement database storage
This commit is contained in:
+48
-4
@@ -1,17 +1,61 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/ardeman/project-legalgo-go/database"
|
||||
repository "github.com/ardeman/project-legalgo-go/internal/accessor"
|
||||
internalhttp "github.com/ardeman/project-legalgo-go/internal/api/http"
|
||||
pkgconfig "github.com/ardeman/project-legalgo-go/internal/config"
|
||||
"github.com/ardeman/project-legalgo-go/internal/services"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/joho/godotenv"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := godotenv.Load(); err != nil {
|
||||
log.Fatal("cannot load environment file")
|
||||
}
|
||||
}
|
||||
|
||||
func run(lc fx.Lifecycle, db *database.DB, apiRouter chi.Router) {
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
fmt.Println("Application has started...")
|
||||
// Run migration
|
||||
if err := db.Migrate(); err != nil {
|
||||
log.Fatal("Migration failed: ", err)
|
||||
}
|
||||
|
||||
pkgconfig.Router(apiRouter)
|
||||
|
||||
return nil
|
||||
},
|
||||
OnStop: func(ctx context.Context) error {
|
||||
fmt.Println("Shutting down...")
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
fx.New(
|
||||
app := fx.New(
|
||||
database.Module,
|
||||
repository.Module,
|
||||
internalhttp.Module,
|
||||
fx.Invoke(func(apiRouter chi.Router) {
|
||||
pkgconfig.Router(apiRouter)
|
||||
}),
|
||||
services.Module,
|
||||
fx.Invoke(run),
|
||||
)
|
||||
|
||||
if err := app.Start(context.Background()); err != nil {
|
||||
log.Fatal("Error starting app:", err)
|
||||
}
|
||||
|
||||
// Wait for the app to stop gracefully
|
||||
if err := app.Stop(context.Background()); err != nil {
|
||||
log.Fatal("Error stopping app:", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user